Ensure that a project BOM includes the build parts of its subprojects

This commit is contained in:
Jan Böhmer 2022-12-29 17:52:13 +01:00
parent 9aa6e714f2
commit ef6d30e04b
3 changed files with 37 additions and 1 deletions

View file

@ -31,6 +31,7 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException; use InvalidArgumentException;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/** /**
* Class AttachmentType. * Class AttachmentType.
@ -280,6 +281,34 @@ class Project extends AbstractStructuralDBElement
} }
} }
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
//If this project has subprojects, and these have builds part, they must be included in the BOM
foreach ($this->getChildren() as $child) {
/** @var $child Project */
if ($child->getBuildPart() === null) {
continue;
}
//We have to search all bom entries for the build part
$found = false;
foreach ($this->getBomEntries() as $bom_entry) {
if ($bom_entry->getPart() === $child->getBuildPart()) {
$found = true;
break;
}
}
//When the build part is not found, we have to add an error
if (!$found) {
$context->buildViolation('project.bom_has_to_include_all_subelement_parts')
->atPath('bom_entries')
->setParameter('%project_name%', $child->getName())
->setParameter('%part_name%', $child->getBuildPart()->getName())
->addViolation();
}
}
}
} }

View file

@ -41,6 +41,7 @@
{% block additional_panes %} {% block additional_panes %}
<div class="tab-pane" id="bom"> <div class="tab-pane" id="bom">
{% form_theme form.bom_entries with ['Form/collection_types_layout.html.twig'] %} {% form_theme form.bom_entries with ['Form/collection_types_layout.html.twig'] %}
{{ form_errors(form.bom_entries) }}
{{ form_widget(form.bom_entries) }} {{ form_widget(form.bom_entries) }}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -269,5 +269,11 @@
<target>You can not add a project's own builds part to the BOM.</target> <target>You can not add a project's own builds part to the BOM.</target>
</segment> </segment>
</unit> </unit>
<unit id="2x2XDI_" name="project.bom_has_to_include_all_subelement_parts">
<segment>
<source>project.bom_has_to_include_all_subelement_parts</source>
<target>The project BOM has to include all subprojects builds parts. Part %part_name% of project %project_name% missing!</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>