-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: limits for category combinations [DHIS2-18521] #19374
Changes from 3 commits
1ab7ca2
23590ae
5ac26b9
6477534
b944f90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
|
||
import static org.hisp.dhis.system.deletion.DeletionVeto.ACCEPT; | ||
|
||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hisp.dhis.system.deletion.DeletionVeto; | ||
import org.hisp.dhis.system.deletion.IdObjectDeletionHandler; | ||
|
@@ -58,8 +59,10 @@ private DeletionVeto allowDeleteCategory(Category category) { | |
} | ||
|
||
private void deleteCategoryOptionCombo(CategoryOptionCombo categoryOptionCombo) { | ||
for (CategoryCombo categoryCombo : categoryService.getAllCategoryCombos()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: I am not sure why we would loop over all CCs when there is just one linked to the COC which needs unlinking. Also I added a check if the un-linking isn't already done because if this was called as a consequence of deleting the CC it has and so the update should not be called again on the CC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not needed, this is very nice. That could be very costly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I only have my subjective observation from test and debugging but I found this because an deletion attempt would just spin my PC out of control so I had to kill the server, then step through it to see what was going on, which was when I found this. I then redid the deletion and it still was super slow but the server was at least responsive. |
||
categoryCombo.getOptionCombos().remove(categoryOptionCombo); | ||
CategoryCombo categoryCombo = categoryOptionCombo.getCategoryCombo(); | ||
Set<CategoryOptionCombo> optionCombos = categoryCombo.getOptionCombos(); | ||
if (optionCombos.contains(categoryOptionCombo)) { | ||
optionCombos.remove(categoryOptionCombo); | ||
idObjectManager.updateNoAcl(categoryCombo); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2004-2024, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.dxf2.metadata.objectbundle.hooks; | ||
|
||
import java.util.function.Consumer; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hisp.dhis.category.CategoryCombo; | ||
import org.hisp.dhis.category.CategoryOptionCombo; | ||
import org.hisp.dhis.category.CategoryService; | ||
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle; | ||
import org.hisp.dhis.feedback.ConflictException; | ||
import org.hisp.dhis.feedback.ErrorReport; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CategoryComboObjectBundleHook extends AbstractObjectBundleHook<CategoryCombo> { | ||
|
||
private final CategoryService categoryService; | ||
|
||
@Override | ||
public void validate(CategoryCombo combo, ObjectBundle bundle, Consumer<ErrorReport> addReports) { | ||
checkIsValid(combo, addReports); | ||
} | ||
|
||
private void checkIsValid(CategoryCombo combo, Consumer<ErrorReport> addReports) { | ||
try { | ||
categoryService.validate(combo); | ||
} catch (ConflictException ex) { | ||
addReports.accept(new ErrorReport(CategoryOptionCombo.class, ex.getCode(), ex.getArgs())); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2004-2024, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.hisp.dhis.dxf2.metadata.objectbundle.hooks; | ||
|
||
import java.util.function.Consumer; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hisp.dhis.category.Category; | ||
import org.hisp.dhis.category.CategoryOptionCombo; | ||
import org.hisp.dhis.category.CategoryService; | ||
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle; | ||
import org.hisp.dhis.feedback.ConflictException; | ||
import org.hisp.dhis.feedback.ErrorReport; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CategoryObjectBundleHook extends AbstractObjectBundleHook<Category> { | ||
|
||
private final CategoryService categoryService; | ||
|
||
@Override | ||
public void validate(Category category, ObjectBundle bundle, Consumer<ErrorReport> addReports) { | ||
checkIsValid(category, addReports); | ||
} | ||
|
||
private void checkIsValid(Category category, Consumer<ErrorReport> addReports) { | ||
try { | ||
categoryService.validate(category); | ||
} catch (ConflictException ex) { | ||
addReports.accept(new ErrorReport(CategoryOptionCombo.class, ex.getCode(), ex.getArgs())); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this message can mirror the other 2?
..... cannot have more than x combinations, but had: y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is worded differently because it is different. The combinations do not exist (yet) and when the validation fails we also don't create them, so I thought wording it "but had" is confusing if you know what is going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok cool. There is a typo in
bud
. Should bebut
.