|
@@ -20,6 +20,7 @@ use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Enum\Education\CycleEnum;
|
|
use App\Enum\Education\CycleEnum;
|
|
|
use App\Enum\Network\NetworkEnum;
|
|
use App\Enum\Network\NetworkEnum;
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
|
|
+use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Enum\Person\AddressPostalPersonTypeEnum;
|
|
use App\Enum\Person\AddressPostalPersonTypeEnum;
|
|
|
use App\Repository\Core\CountryRepository;
|
|
use App\Repository\Core\CountryRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
@@ -34,7 +35,6 @@ use Elastica\Param;
|
|
|
use libphonenumber\NumberParseException;
|
|
use libphonenumber\NumberParseException;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
-use SebastianBergmann\Type\RuntimeException;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\String\ByteString;
|
|
use Symfony\Component\String\ByteString;
|
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
@@ -314,13 +314,17 @@ class OrganizationFactory
|
|
|
*/
|
|
*/
|
|
|
protected function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
|
|
protected function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
|
|
|
{
|
|
{
|
|
|
|
|
+ $country = $this->countryRepository->find($organizationCreationRequest->getCountryId());
|
|
|
|
|
+ if (!$country) {
|
|
|
|
|
+ throw new \RuntimeException('No country found for id ' . $organizationCreationRequest->getCountryId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$addressPostal = new AddressPostal();
|
|
$addressPostal = new AddressPostal();
|
|
|
$addressPostal->setStreetAddress($organizationCreationRequest->getStreetAddress1());
|
|
$addressPostal->setStreetAddress($organizationCreationRequest->getStreetAddress1());
|
|
|
$addressPostal->setStreetAddressSecond($organizationCreationRequest->getStreetAddress2());
|
|
$addressPostal->setStreetAddressSecond($organizationCreationRequest->getStreetAddress2());
|
|
|
$addressPostal->setStreetAddressThird($organizationCreationRequest->getStreetAddress3());
|
|
$addressPostal->setStreetAddressThird($organizationCreationRequest->getStreetAddress3());
|
|
|
$addressPostal->setPostalCode($organizationCreationRequest->getPostalCode());
|
|
$addressPostal->setPostalCode($organizationCreationRequest->getPostalCode());
|
|
|
$addressPostal->setAddressCity($organizationCreationRequest->getCity());
|
|
$addressPostal->setAddressCity($organizationCreationRequest->getCity());
|
|
|
- $country = $this->countryRepository->find($organizationCreationRequest->getCountryId());
|
|
|
|
|
$addressPostal->setAddressCountry($country);
|
|
$addressPostal->setAddressCountry($country);
|
|
|
$this->entityManager->persist($addressPostal);
|
|
$this->entityManager->persist($addressPostal);
|
|
|
|
|
|
|
@@ -343,6 +347,9 @@ class OrganizationFactory
|
|
|
protected function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
|
|
protected function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
|
|
|
{
|
|
{
|
|
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
|
|
|
|
+ if (!$phoneUtil->isPossibleNumber($organizationCreationRequest->getPhoneNumber())) {
|
|
|
|
|
+ throw new \RuntimeException("Phone number is invalid or missing");
|
|
|
|
|
+ }
|
|
|
$phoneNumber = $phoneUtil->parse($organizationCreationRequest->getPhoneNumber());
|
|
$phoneNumber = $phoneUtil->parse($organizationCreationRequest->getPhoneNumber());
|
|
|
|
|
|
|
|
$contactPoint = new ContactPoint();
|
|
$contactPoint = new ContactPoint();
|
|
@@ -370,6 +377,13 @@ class OrganizationFactory
|
|
|
throw new \RuntimeException('No parent organization found for id ' . $organizationCreationRequest->getParentId());
|
|
throw new \RuntimeException('No parent organization found for id ' . $organizationCreationRequest->getParentId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($parent->getSettings()->getProduct() !== SettingsProductEnum::MANAGER) {
|
|
|
|
|
+ throw new \RuntimeException(
|
|
|
|
|
+ "Parent organization must have the product 'manager' (actual product: " .
|
|
|
|
|
+ $organizationCreationRequest->getParentId() . ")"
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$networkOrganization = $this->organizationUtils->getActiveNetworkOrganization($parent);
|
|
$networkOrganization = $this->organizationUtils->getActiveNetworkOrganization($parent);
|
|
|
if (!$networkOrganization) {
|
|
if (!$networkOrganization) {
|
|
|
throw new \RuntimeException('No network found for parent ' . $organizationCreationRequest->getParentId());
|
|
throw new \RuntimeException('No network found for parent ' . $organizationCreationRequest->getParentId());
|
|
@@ -382,6 +396,13 @@ class OrganizationFactory
|
|
|
if (!preg_match("/FR\d{12}/", $organizationCreationRequest->getIdentifier())) {
|
|
if (!preg_match("/FR\d{12}/", $organizationCreationRequest->getIdentifier())) {
|
|
|
throw new \RuntimeException("CMF identifier is missing or invalid.");
|
|
throw new \RuntimeException("CMF identifier is missing or invalid.");
|
|
|
}
|
|
}
|
|
|
|
|
+ if ($this
|
|
|
|
|
+ ->organizationRepository
|
|
|
|
|
+ ->count(
|
|
|
|
|
+ ['identifier' => $organizationCreationRequest->getIdentifier()]
|
|
|
|
|
+ ) > 0) {
|
|
|
|
|
+ throw new \RuntimeException("CMF identifier is already registered : '" . $organizationCreationRequest->getIdentifier() ."'");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$networkOrganization = new NetworkOrganization();
|
|
$networkOrganization = new NetworkOrganization();
|