@@ -112,6 +112,45 @@ public class PlateController extends SpringActionController
112112 private static final SpringActionController .DefaultActionResolver _actionResolver = new DefaultActionResolver (PlateController .class );
113113 private static final Logger LOG = LogHelper .getLogger (PlateController .class , "Controller for plate related actions" );
114114
115+ record SubmittedGroup (int rowId , String type , String name , List <PlatePosition > positions , Map <String , Object > properties )
116+ {
117+ public static SubmittedGroup from (JSONObject g )
118+ {
119+ int rowId = g .optInt ("rowId" , -1 );
120+ String type = g .getString ("type" );
121+ String name = g .getString ("name" );
122+ JSONArray posArr = g .optJSONArray ("positions" );
123+ List <PlatePosition > positions = new ArrayList <>();
124+ if (posArr != null )
125+ {
126+ for (int j = 0 ; j < posArr .length (); j ++)
127+ {
128+ JSONObject p = posArr .getJSONObject (j );
129+ positions .add (PlatePosition .from (p ));
130+ }
131+ }
132+ JSONObject propsObj = g .optJSONObject ("properties" );
133+ Map <String , Object > props = new HashMap <>();
134+ if (propsObj != null )
135+ {
136+ for (String key : propsObj .keySet ())
137+ {
138+ Object val = propsObj .get (key );
139+ props .put (key , val == JSONObject .NULL ? null : val );
140+ }
141+ }
142+ return new SubmittedGroup (rowId , type , name , positions , props );
143+ }
144+ }
145+
146+ record PlatePosition (int row , int col )
147+ {
148+ public static PlatePosition from (JSONObject p )
149+ {
150+ return new PlatePosition (p .getInt ("row" ), p .getInt ("col" ));
151+ }
152+ }
153+
115154 public PlateController ()
116155 {
117156 setActionResolver (_actionResolver );
@@ -165,7 +204,7 @@ public static class PlateListAction extends SimpleViewAction<ReturnUrlForm>
165204 public ModelAndView getView (ReturnUrlForm form , BindException errors )
166205 {
167206 setHelpTopic ("editPlateTemplate" );
168- List <Plate > plateTemplates = PlateService .get ().getPlates (getContainer ())
207+ List <? extends Plate > plateTemplates = PlateService .get ().getPlates (getContainer ())
169208 .stream ()
170209 .filter (p -> !TsvPlateLayoutHandler .TYPE .equalsIgnoreCase (p .getAssayType ()))
171210 .toList ();
@@ -180,6 +219,7 @@ public void addNavTrail(NavTree root)
180219 }
181220 }
182221
222+ /** Delete soon! */
183223 @ RequiresAnyOf ({InsertPermission .class , DesignAssayPermission .class })
184224 public static class DesignerServiceAction extends GWTServiceAction
185225 {
@@ -417,7 +457,7 @@ public Object execute(SaveTemplateForm form, BindException errors) throws Except
417457 }
418458
419459 boolean updateExisting = false ;
420- Plate plate ;
460+ PlateImpl plate ;
421461 if (rowId > 0 )
422462 {
423463 plate = PlateManager .get ().getPlate (getContainer (), rowId );
@@ -447,42 +487,16 @@ public Object execute(SaveTemplateForm form, BindException errors) throws Except
447487 plate .setProperties (plateProperties );
448488
449489 // Parse groups from JSON
450- List <Map < String , Object > > submittedGroups = new ArrayList <>();
490+ List <SubmittedGroup > submittedGroups = new ArrayList <>();
451491 Set <Integer > submittedGroupIds = new HashSet <>();
452492 if (groupsJson != null )
453493 {
454494 for (int i = 0 ; i < groupsJson .length (); i ++)
455495 {
456- JSONObject g = groupsJson .getJSONObject (i );
457- Map <String , Object > gm = new HashMap <>();
458- gm .put ("rowId" , g .optInt ("rowId" , -1 ));
459- gm .put ("type" , g .getString ("type" ));
460- gm .put ("name" , g .getString ("name" ));
461- JSONArray posArr = g .optJSONArray ("positions" );
462- List <int []> positions = new ArrayList <>();
463- if (posArr != null )
464- {
465- for (int j = 0 ; j < posArr .length (); j ++)
466- {
467- JSONObject p = posArr .getJSONObject (j );
468- positions .add (new int []{p .getInt ("row" ), p .getInt ("col" )});
469- }
470- }
471- gm .put ("positions" , positions );
472- JSONObject propsObj = g .optJSONObject ("properties" );
473- Map <String , Object > props = new HashMap <>();
474- if (propsObj != null )
475- {
476- for (String key : propsObj .keySet ())
477- {
478- Object val = propsObj .get (key );
479- props .put (key , val == JSONObject .NULL ? null : val );
480- }
481- }
482- gm .put ("properties" , props );
483- submittedGroups .add (gm );
484- if ((int ) gm .get ("rowId" ) > 0 )
485- submittedGroupIds .add ((int ) gm .get ("rowId" ));
496+ SubmittedGroup g = SubmittedGroup .from (groupsJson .getJSONObject (i ));
497+ submittedGroups .add (g );
498+ if (g .rowId > 0 )
499+ submittedGroupIds .add (g .rowId );
486500 }
487501 }
488502
@@ -491,14 +505,14 @@ public Object execute(SaveTemplateForm form, BindException errors) throws Except
491505 for (WellGroup existingGroup : existingWellGroups )
492506 {
493507 if (existingGroup .getRowId () != null && !submittedGroupIds .contains (existingGroup .getRowId ()))
494- (( PlateImpl ) plate ) .markWellGroupForDeletion (existingGroup );
508+ plate .markWellGroupForDeletion (existingGroup );
495509 }
496510
497511 // Update or create well groups
498- for (Map < String , Object > gm : submittedGroups )
512+ for (SubmittedGroup gm : submittedGroups )
499513 {
500- int gRowId = ( int ) gm .get ( " rowId" );
501- String groupTypeName = ( String ) gm .get ( " type" );
514+ int gRowId = gm .rowId ( );
515+ String groupTypeName = gm .type ( );
502516 WellGroup .Type groupType ;
503517 try
504518 {
@@ -508,14 +522,12 @@ public Object execute(SaveTemplateForm form, BindException errors) throws Except
508522 {
509523 throw new ApiUsageException ("Unknown well group type: '" + groupTypeName + "'" );
510524 }
511- @ SuppressWarnings ("unchecked" )
512- List <int []> posList = (List <int []>) gm .get ("positions" );
525+ List <PlatePosition > posList = gm .positions ();
513526 List <Position > positions = new ArrayList <>();
514- for (int [] p : posList )
515- positions .add (plate .getPosition (p [ 0 ] , p [ 1 ] ));
527+ for (PlatePosition p : posList )
528+ positions .add (plate .getPosition (p . row , p . col ));
516529
517- @ SuppressWarnings ("unchecked" )
518- Map <String , Object > props = (Map <String , Object >) gm .get ("properties" );
530+ Map <String , Object > props = gm .properties ();
519531
520532 WellGroupImpl group ;
521533 if (updateExisting && gRowId > 0 )
@@ -524,15 +536,15 @@ public Object execute(SaveTemplateForm form, BindException errors) throws Except
524536 if (existing == null )
525537 throw new Exception ("Well group " + gRowId + " was not found." );
526538 if (existing .getType () != groupType )
527- throw new Exception ("Well group type cannot be changed: " + gm .get ( " name" ));
528- existing .setName (( String ) gm .get ( " name" ) );
539+ throw new Exception ("Well group type cannot be changed: " + gm .name ( ));
540+ existing .setName (gm .name );
529541 existing .setPositions (positions );
530- (( PlateImpl ) plate ) .storeWellGroup (existing );
542+ plate .storeWellGroup (existing );
531543 group = existing ;
532544 }
533545 else
534546 {
535- group = ( WellGroupImpl ) plate .addWellGroup (( String ) gm .get ( " name" ) , groupType , positions );
547+ group = plate .addWellGroup (gm .name , groupType , positions );
536548 }
537549 group .setProperties (props );
538550 }
@@ -579,6 +591,7 @@ public void addNavTrail(NavTree root)
579591 }
580592 }
581593
594+ /** Delete soon! */
582595 @ RequiresAnyOf ({InsertPermission .class , DesignAssayPermission .class })
583596 public class DesignerGwtAction extends SimpleViewAction <DesignerForm >
584597 {
@@ -664,7 +677,7 @@ public static class CopyTemplateBean
664677 private HtmlString _treeHtml ;
665678 private Plate _plate ;
666679 private String _selectedDestination ;
667- private List <Plate > _destinationTemplates ;
680+ private List <? extends Plate > _destinationTemplates ;
668681
669682 public CopyTemplateBean (final Container container , final User user , final Integer plateId , final String selectedDestination )
670683 {
@@ -1083,7 +1096,7 @@ public Object execute(CreatePlateForm form, BindException errors) throws Excepti
10831096 PlateImpl newPlate = new PlateImpl (getContainer (), form .getName (), form .getBarcode (), form .getAssayType (), _plateType );
10841097 if (form .getData () == null && form .getTemplateId () != null && TsvPlateLayoutHandler .TYPE .equalsIgnoreCase (newPlate .getAssayType ()))
10851098 {
1086- newPlate = ( PlateImpl ) PlateManager .get ().copyPlate (
1099+ newPlate = PlateManager .get ().copyPlate (
10871100 getContainer (),
10881101 getUser (),
10891102 form .getTemplateId (),
@@ -1104,7 +1117,7 @@ public Object execute(CreatePlateForm form, BindException errors) throws Excepti
11041117 if (form .isTemplate () && data == null )
11051118 data = PlateManager .get ().prepareEmptyPlateTemplateData (getContainer (), _plateType );
11061119
1107- newPlate = ( PlateImpl ) PlateManager .get ().createAndSavePlate (getContainer (), getUser (), newPlate , form .getPlateSetId (), data );
1120+ newPlate = PlateManager .get ().createAndSavePlate (getContainer (), getUser (), newPlate , form .getPlateSetId (), data );
11081121 }
11091122
11101123 return success (newPlate );
0 commit comments