/**
  * Prefix organization type to OrgId
  * @param  string  $id
  * @param  boolean $parent Default false. Use it to prefix parent organization type.
  * @return string
  */
 public static function buildOrgIdByOrganizationProto(Organization $proto)
 {
     $map = array(OrgPB\OrgType::MASTER => "Application\\Model\\Mapper\\Organization\\OrgMasterMapper", OrgPB\OrgType::SERVICE_PROVIDER => "Application\\Model\\Mapper\\Organization\\OrgServiceProviderMapper", OrgPB\OrgType::CUSTOMER => "Application\\Model\\Mapper\\Organization\\OrgCustomerMapper");
     $id = $proto->getId();
     if (isset($map[$proto->getType()])) {
         $mapperClass = $map[$proto->getType()];
         $id = $mapperClass::buildOrgId($id);
     }
     return $id;
 }
 protected function _mapSubscriptionSnapshotTarget($data)
 {
     if (isset($data['organization'])) {
         $org = new \Application\Proto\Organization();
         $org->setType($data['organization']['type']);
         $org->setId($data['organization']['id']);
         $data['organization'] = OrganizationMapper::buildOrgIdByOrganizationProto($org);
     }
     return $data;
 }
 protected function _constructProtoSubscriptionSnapshotReportEricsson($params, $proto)
 {
     $orgId = OrganizationMapper::cleanOrgId($params['orgId']);
     $orgType = OrganizationMapper::getTypeByOrgId($params['orgId']);
     switch ($orgType) {
         case OrgMasterModel::ORG_TYPE:
             $type = PbOrg\OrgType::MASTER;
             break;
         case OrgServiceProviderModel::ORG_TYPE:
             $type = PbOrg\OrgType::SERVICE_PROVIDER;
             break;
         case OrgCustomerModel::ORG_TYPE:
             $type = PbOrg\OrgType::CUSTOMER;
             break;
         default:
             throw new InvalidArgumentException("Invalid organization type " . $orgType);
     }
     $target = new PbReport\Target\DailySSTarget();
     $targetOrg = new PbOrg();
     $targetOrg->setType($type);
     $targetOrg->setId($orgId);
     $target->setOrganization($targetOrg);
     $proto->setTarget($target);
     $proto->setDateDaily($params['dateDaily']);
     return $proto;
 }
 /**
  * Creates a organization proto message from organizationId
  *
  * @param \Application\Proto\Organization $orgId
  */
 protected function _createOrganization($orgId)
 {
     $orgTypeMap = array(OrgSuperModel::ORG_TYPE => Organization\OrgType::MASTER, OrgMasterModel::ORG_TYPE => Organization\OrgType::MASTER, OrgServiceProviderModel::ORG_TYPE => Organization\OrgType::SERVICE_PROVIDER, OrgCustomerModel::ORG_TYPE => Organization\OrgType::CUSTOMER, OrgAggregatorModel::ORG_TYPE => Organization\OrgType::AGGREGATOR);
     $type = OrganizationMapper::getTypeByOrgId($orgId);
     if (!isset($orgTypeMap[$type])) {
         return null;
     }
     $orgType = $orgTypeMap[$type];
     if ($type != OrgSuperModel::ORG_TYPE) {
         $orgId = OrganizationMapper::cleanOrgId($orgId);
     } else {
         $orgId = substr($orgId, 0, 32);
         if (strlen($orgId) < 32) {
             $orgId .= str_repeat('0', 32 - strlen($orgId));
         }
     }
     $org = new Organization();
     $org->setType($orgType);
     $org->setId($orgId);
     return $org;
 }