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 InvalidArgumentException;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* 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();
}
}
}
}