6262import org .hisp .dhis .user .UserDetails ;
6363import org .hisp .dhis .webapi .controller .AbstractCrudController ;
6464import org .springframework .http .HttpStatus ;
65+ import org .springframework .web .bind .annotation .PatchMapping ;
66+ import org .springframework .web .bind .annotation .PathVariable ;
6567import org .springframework .web .bind .annotation .PostMapping ;
68+ import org .springframework .web .bind .annotation .PutMapping ;
6669import org .springframework .web .bind .annotation .RequestBody ;
6770import org .springframework .web .bind .annotation .RequestMapping ;
6871import org .springframework .web .bind .annotation .ResponseStatus ;
@@ -116,7 +119,14 @@ public WebMessage mergeCategoryOptionCombos(@RequestBody MergeParams params)
116119 * @param request request
117120 * @return WebMessage
118121 */
122+ @ OpenApi .Description (
123+ """
124+ Creating a single CategoryOptionCombo is not allowed. They should be either:
125+ - left to be auto-generated by the system
126+ - imported through the metadata endpoint
127+ """ )
119128 @ Override
129+ @ PostMapping (produces = APPLICATION_JSON_VALUE )
120130 public WebMessage postJsonObject (HttpServletRequest request ) {
121131 return WebMessageUtils .conflict (E1129 );
122132 }
@@ -130,10 +140,22 @@ public WebMessage postJsonObject(HttpServletRequest request) {
130140 * Metadata import endpoint has very different behaviour for importing {@link
131141 * CategoryOptionCombo}s and is not suitable for individual updates.
132142 */
143+ @ OpenApi .Description (
144+ """
145+ Updating a CategoryOptionCombos is restricted, only 3 fields are updatable
146+ through the PUT endpoint:
147+ - attributeValues
148+ - code
149+ - ignoreApproval
150+ Metadata import has very different behaviour for importing CategoryOptionCombos and is
151+ not suitable for individual updates.
152+ """ )
133153 @ Override
134- public WebMessage putJsonObject (String pvUid , UserDetails currentUser , HttpServletRequest request )
154+ @ PutMapping (value = "/{uid}" , produces = APPLICATION_JSON_VALUE )
155+ public WebMessage putJsonObject (
156+ @ PathVariable String uid , UserDetails currentUser , HttpServletRequest request )
135157 throws NotFoundException , ForbiddenException , ConflictException , IOException {
136- CategoryOptionCombo persisted = getEntity (pvUid );
158+ CategoryOptionCombo persisted = getEntity (uid );
137159 updatePermissionCheck (currentUser , persisted );
138160
139161 CategoryOptionComboUpdateDto cocUpdate =
@@ -151,9 +173,20 @@ public WebMessage putJsonObject(String pvUid, UserDetails currentUser, HttpServl
151173 * Metadata import has very different behaviour for importing {@link CategoryOptionCombo}s and is
152174 * not suitable for individual updates.
153175 */
176+ @ OpenApi .Description (
177+ """
178+ Updating a CategoryOptionCombos is restricted, only 3 fields are updatable
179+ through the PATCH endpoint:
180+ - attributeValues
181+ - code
182+ - ignoreApproval
183+ Metadata import has very different behaviour for importing CategoryOptionCombos and is
184+ not suitable for individual updates.
185+ """ )
154186 @ Override
187+ @ PatchMapping (value = "/{uid}" , produces = APPLICATION_JSON_VALUE )
155188 public WebMessage patchObject (
156- String pvUid ,
189+ @ PathVariable String uid ,
157190 Map <String , String > rpParameters ,
158191 UserDetails currentUser ,
159192 HttpServletRequest request )
@@ -162,7 +195,7 @@ public WebMessage patchObject(
162195 ConflictException ,
163196 IOException ,
164197 JsonPatchException {
165- CategoryOptionCombo persisted = getEntity (pvUid );
198+ CategoryOptionCombo persisted = getEntity (uid );
166199 updatePermissionCheck (currentUser , persisted );
167200
168201 JsonPatch patch = jsonMapper .readValue (request .getInputStream (), JsonPatch .class );
0 commit comments