/** * Validate element value * * If a translation adapter is registered, any error messages will be * translated according to the current locale, using the given error code; * if no matching translation is found, the original message will be * utilized. * * Note: The *filtered* value is validated. * * @param array $data * @param mixed $context * @return boolean */ public function isValid($data, $context = null, $removeNotPresentFields = false) { if (!($data instanceof AlarmRuleModel || is_array($data))) { $this->_messages = array(); $this->_messages[self::NOT_ALARM_RULE] = $this->_messageAlarmRule[self::NOT_ALARM_RULE]; return false; } if (!parent::isValid($data, $context, $removeNotPresentFields)) { return false; } if (!$data instanceof AlarmRuleModel) { $data = new AlarmRuleModel($data); } switch ($data->universeType) { case AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP: case AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP: $validator = new \App_Validate_Ericsson_CommercialGroupExistsById(); break; case AlarmRuleModel::UNIVERSE_BILLING_ACCOUNT: $validator = new \App_Validate_Ericsson_BillingAccountExistsById(array('organizationIdField' => 'customerId')); break; case AlarmRuleModel::UNIVERSE_CUSTOMER: $validator = new \App_Validate_Ericsson_OrganizationExistsById(); $validator->setOrganizationType(OrgCustomerModel::ORG_TYPE); break; case AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_SUPERVISION_GROUP: $validator = new \App_Validate_Amplia_SupervisionGroupExistsByName(); break; } if (!$validator->isValid($data->universeId, $data->exportData())) { $this->_messages['universeId'] = $validator->getMessages(); return false; } return true; }
public function testValidateOrgMasterNotExists() { $result = $this->_validator->isValid("master-noExistsId"); $this->assertFalse($result); $messages = $this->_validator->getMessages(); $this->assertArrayHasKey(App_Validate_Ericsson_OrganizationExistsById::ERROR_ORGANIZATION_NOT_FOUND, $messages); }
public function postAction() { $reqData = $this->_helper->requestData(); $reqKeys = array_keys($reqData); if (count($reqKeys) != 1) { throw new InvalidArgumentException("Report type is required as a main key"); } $type = $reqKeys[0]; $params = $reqData[$type]; // Check report permissions by type $dumpReport = new ReportModel(); $dumpReport->setType($type); if ($type !== ReportModel::AUDIT_LOG) { $this->_helper->allowed('create', $dumpReport); } else { $dumpAudit = new \Application\Model\AuditLogModel(); $this->_helper->allowed('create', $dumpAudit); } // Custom download report name switch ($type) { case ReportModel::KPI_MONTHLY: $fileType = 'arpu'; break; default: $fileType = $type; } if ($type !== ReportModel::AUDIT_LOG) { try { $headers = ReportAsyncService::getInstance()->getHeaders($type, $params); $dumpReport->setHeaders($headers); $this->_helper->filterNotAllowedCols("read_field", $dumpReport); $columns = array_keys($dumpReport->headers); if (isset($params['requiredFields'])) { $columns = array_intersect($columns, $params['requiredFields']); } $params['columns'] = $columns; } catch (InvalidArgumentException $e) { \App::log()->info("Report {$type} does not have defined headers"); } } $params['fileType'] = $fileType; $dumpReport->params = $params; //validate organization exists $validateOrgExist = new App_Validate_Ericsson_OrganizationExistsById(); if (isset($params['orgId'])) { $result = $validateOrgExist->isValid($params['orgId']); if (!$result) { throw new InvalidArgumentException("Invalid parameter value: orgId. Supported values are orgId belonging to the current organization"); } } try { $this->_service->create($dumpReport); } catch (Application\Exceptions\NotFoundException $e) { if ($e->getMessage() == "Resource supervisionGroup does not exists") { throw new InvalidArgumentException("Invalid parameter value supervisionGroup"); } throw $e; } $url = $this->getFrontController()->getRouter()->assemble(array('controller' => $this->getRequest()->getControllerName(), 'action' => $this->getRequest()->getActionName(), 'id' => $dumpReport->getId())); $this->getResponse()->setHeader('Location', $url); $this->getResponse()->setHttpResponseCode(202); }