@@ -684,39 +684,55 @@ public ApiResponse execute(RecordDeleteForm form, BindException errors)
684684 }
685685 }
686686
687+ public static class UpdateEHRIndicesForm
688+ {
689+ private String _operation ;
690+
691+ public String getOperation ()
692+ {
693+ return _operation ;
694+ }
695+
696+ public void setOperation (String operation )
697+ {
698+ _operation = operation ;
699+ }
700+ }
701+
687702 @ RequiresPermission (AdminPermission .class )
688- public static class DropEHRIndicesAction extends MutatingApiAction <Object >
703+ public static class UpdateEHRIndicesAction extends MutatingApiAction <UpdateEHRIndicesForm >
689704 {
690705 @ Override
691- public ApiResponse execute ( Object form , BindException errors )
706+ public void validateForm ( UpdateEHRIndicesForm form , Errors errors )
692707 {
693- try
708+ super .validateForm (form , errors );
709+
710+ if (form .getOperation () == null )
694711 {
695- List <String > messages = EHRManager .get ().dropEHRIndices (getContainer (), getUser ());
696- Map <String , Object > response = new HashMap <>();
697- response .put ("success" , true );
698- response .put ("messages" , messages );
699- return new ApiSimpleResponse (response );
712+ errors .reject (ERROR_MSG , "Operation parameter is required." );
700713 }
701- catch ( Exception e )
714+ else if (! "add" . equalsIgnoreCase ( form . getOperation ()) && ! "drop" . equalsIgnoreCase ( form . getOperation ()) )
702715 {
703- Map <String , Object > response = new HashMap <>();
704- response .put ("success" , false );
705- response .put ("message" , e .getMessage ());
706- return new ApiSimpleResponse (response );
716+ errors .reject (ERROR_MSG , "Invalid operation. Must be 'add' or 'drop'." );
707717 }
708718 }
709- }
710719
711- @ RequiresPermission (AdminPermission .class )
712- public static class AddEHRIndicesAction extends MutatingApiAction <Object >
713- {
714720 @ Override
715- public ApiResponse execute (Object form , BindException errors )
721+ public ApiResponse execute (UpdateEHRIndicesForm form , BindException errors )
716722 {
717723 try
718724 {
719- List <String > messages = EHRManager .get ().addEHRIndices (getContainer (), getUser ());
725+ List <String > messages ;
726+
727+ if ("drop" .equalsIgnoreCase (form .getOperation ()))
728+ {
729+ messages = EHRManager .get ().dropEHRIndices (getContainer (), getUser ());
730+ }
731+ else
732+ {
733+ messages = EHRManager .get ().addEHRIndices (getContainer (), getUser ());
734+ }
735+
720736 Map <String , Object > response = new HashMap <>();
721737 response .put ("success" , true );
722738 response .put ("messages" , messages );
0 commit comments