diff --git a/marketplace/_config.php b/marketplace/_config.php index 130db30..821443c 100644 --- a/marketplace/_config.php +++ b/marketplace/_config.php @@ -36,4 +36,4 @@ Object::add_extension('OpenStackComponent', 'OpenStackComponentAdminUI'); Object::add_extension('OpenStackApiVersion', 'OpenStackApiVersionAdminUI'); Object::add_extension('OpenStackRelease', 'OpenStackReleaseAdminUI'); Object::add_extension('OpenStackReleaseSupportedApiVersion', 'OpenStackReleaseSupportedApiVersionAdminUI'); -Object::add_extension('MarketPlaceAllowedInstance', 'MarketPlaceAllowedInstanceAdminUI'); +Object::add_extension('MarketPlaceAllowedInstance', 'MarketPlaceAllowedInstanceAdminUI'); \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/clouds/AvailabilityZoneDraft.php b/marketplace/code/infrastructure/active_records/clouds/AvailabilityZoneDraft.php new file mode 100644 index 0000000..782b9db --- /dev/null +++ b/marketplace/code/infrastructure/active_records/clouds/AvailabilityZoneDraft.php @@ -0,0 +1,63 @@ + 'ENGINE=InnoDB'); + + static $db = array( + 'Name' => 'Varchar', + ); + + static $has_one = array( + 'Location' => 'DataCenterLocationDraft', + ); + + static $indexes = array( + 'Location_Name' => array('type'=>'unique', 'value'=>'LocationID,Name'), + ); + + /** + * @return mixed|string + */ + public function getName() + { + return $this->getField('Name'); + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->setField('Name',$name); + } + + /** + * @return DataObject|IDataCenterLocation + */ + public function getLocation() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Location','AvailabilityZones')->getTarget(); + } + + /** + * @param IDataCenterLocation $location + */ + public function setLocation(IDataCenterLocation $location) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'Location','AvailabilityZones')->setTarget($location); + } + + /** + * @return int + */ + public function getIdentifier() + { + return (int)$this->getField('ID'); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/clouds/CloudServiceDraft.php b/marketplace/code/infrastructure/active_records/clouds/CloudServiceDraft.php index e0c0915..a9531fc 100644 --- a/marketplace/code/infrastructure/active_records/clouds/CloudServiceDraft.php +++ b/marketplace/code/infrastructure/active_records/clouds/CloudServiceDraft.php @@ -8,10 +8,10 @@ class CloudServiceDraft extends OpenStackImplementationDraft { static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB'); static $has_many = array( - 'DataCenters' => 'DataCenterLocation', + 'DataCenters' => 'DataCenterLocationDraft', //@override - 'Capabilities' => 'CloudServiceOffered', - 'DataCenterRegions' => 'DataCenterRegion', + 'Capabilities' => 'CloudServiceOfferedDraft', + 'DataCenterRegions' => 'DataCenterRegionDraft', ); /** diff --git a/marketplace/code/infrastructure/active_records/clouds/CloudServiceOfferedDraft.php b/marketplace/code/infrastructure/active_records/clouds/CloudServiceOfferedDraft.php new file mode 100644 index 0000000..c87d7a8 --- /dev/null +++ b/marketplace/code/infrastructure/active_records/clouds/CloudServiceOfferedDraft.php @@ -0,0 +1,38 @@ + 'ENGINE=InnoDB'); + + + static $many_many = array( + 'PricingSchemas' => 'PricingSchemaType', + ); + + /** + * @return IPricingSchemaType[] + */ + public function getPricingSchemas() + { + return AssociationFactory::getInstance()->getMany2ManyAssociation($this,'PricingSchemas')->toArray(); + } + + /** + * @param IPricingSchemaType $pricing_schema + * @return void + */ + public function addPricingSchema(IPricingSchemaType $pricing_schema) + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'PricingSchemas')->add($pricing_schema); + } + + public function clearPricingSchemas(){ + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'PricingSchemas')->removeAll(); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/clouds/DataCenterLocationDraft.php b/marketplace/code/infrastructure/active_records/clouds/DataCenterLocationDraft.php new file mode 100644 index 0000000..f58e45c --- /dev/null +++ b/marketplace/code/infrastructure/active_records/clouds/DataCenterLocationDraft.php @@ -0,0 +1,154 @@ + 'ENGINE=InnoDB'); + + static $db = array( + 'City' => 'Varchar(125)', + 'State' => 'Varchar(50)', + 'Country' => 'Varchar(5)', + 'Lat' => 'Decimal', + 'Lng' => 'Decimal', + ); + + static $has_one = array( + 'CloudService' => 'CloudServiceDraft', + 'DataCenterRegion' => 'DataCenterRegionDraft', + ); + + static $has_many = array( + 'AvailabilityZones' => 'AvailabilityZoneDraft', + ); + + static $indexes = array( + 'City_State_Country_Service_Region' => array('type'=>'unique', 'value'=>'CloudServiceID,DataCenterRegionID,City,Country,State'), + ); + + public function setCountry($country) + { + $this->setField('Country',$country); + } + + public function getCountry() + { + return $this->getField('Country'); + } + + public function setCity($city) + { + $this->setField('City',$city); + } + + public function getCity() + { + return $this->getField('City'); + } + + public function setCloudService(ICloudService $cloud_service) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'CloudService','DataCenters')->setTarget($cloud_service); + } + + public function getCloudService() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'CloudService','DataCenters')->getTarget(); + } + + public function getAvailabilityZones() + { + return AssociationFactory::getInstance()->getOne2ManyAssociation($this,'AvailabilityZones')->toArray(); + } + + public function clearAvailabilityZones() + { + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'AvailabilityZones')->removeAll(); + } + + public function addAvailabilityZone(IAvailabilityZone $az) + { + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'AvailabilityZones')->add($az); + } + + /** + * @return int + */ + public function getIdentifier() + { + return (int)$this->getField('ID'); + } + + /** + * @return string + */ + public function getState() + { + return $this->getField('State'); + } + + /** + * @param string $state + * @return void + */ + public function setState($state) + { + $this->setField('State',$state); + } + + /** + * @param float $lng + * @return void + */ + public function setLng($lng) + { + $this->setField('Lng',$lng); + } + + /** + * @return float + */ + public function getLng() + { + return $this->getField('Lng'); + } + + /** + * @param float $lat + * @return void + */ + public function setLat($lat) + { + $this->setField('Lat',$lat); + } + + /** + * @return float + */ + public function getLat() + { + return $this->getField('Lat'); + } + + /** + * @return IDataCenterRegion + */ + public function getDataCenterRegion() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'DataCenterRegion','Locations')->getTarget(); + } + + /** + * @param IDataCenterRegion $region + * @return void + */ + public function setDataCenterRegion(IDataCenterRegion $region) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'DataCenterRegion','Locations')->setTarget($region); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/clouds/DataCenterRegionDraft.php b/marketplace/code/infrastructure/active_records/clouds/DataCenterRegionDraft.php new file mode 100644 index 0000000..bafc48a --- /dev/null +++ b/marketplace/code/infrastructure/active_records/clouds/DataCenterRegionDraft.php @@ -0,0 +1,128 @@ + 'ENGINE=InnoDB'); + + static $db = array( + 'Name' => 'Varchar(100)', + 'Endpoint' => 'Varchar(512)', + 'Color' => 'Varchar(6)', + ); + + static $has_one = array( + 'CloudService' => 'CloudServiceDraft', + ); + + static $has_many = array( + 'Locations' => 'DataCenterLocationDraft', + ); + + /*static $indexes = array( + 'Name_CloudService' => array('type'=>'unique', 'value'=>'Name,CloudServiceID'), + );*/ + + /** + * @return string + */ + public function getName() + { + return $this->getField('Name'); + } + + /** + * @param string $name + * @return void + */ + public function setName($name) + { + $this->setField('Name',$name); + } + + /** + * @return string + */ + public function getEndpoint() + { + return $this->getField('Endpoint'); + } + + /** + * @param string $endpoint + * @return void + */ + public function setEndpoint($endpoint) + { + $this->setField('Endpoint',$endpoint); + } + + /** + * @return int + */ + public function getIdentifier() + { + return (int)$this->getField('ID'); + } + + /** + * @return ICloudService + */ + public function getCloud() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'CloudService','DataCenterRegions')->getTarget(); + } + + /** + * @param ICloudService $cloud + * @return void + */ + public function setCloud(ICloudService $cloud) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'CloudService','DataCenterRegions')->setTarget($cloud); + } + + /** + * @return IDataCenterLocation[] + */ + public function getLocations() + { + return AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Locations')->toArray(); + } + + /** + * @param IDataCenterLocation $location + * @return void + */ + public function addLocation(IDataCenterLocation $location) + { + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Locations')->add($location); + } + + /** + * @return void + */ + public function clearLocations() + { + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Locations')->removeAll(); + } + + /** + * @return string + */ + public function getColor() + { + return $this->getField('Color'); + } + + /** + * @param string $color + * @return void + */ + public function setColor($color) + { + $this->setField('Color',$color); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/consultants/ConsultantClientDraft.php b/marketplace/code/infrastructure/active_records/consultants/ConsultantClientDraft.php new file mode 100644 index 0000000..8d9c4f7 --- /dev/null +++ b/marketplace/code/infrastructure/active_records/consultants/ConsultantClientDraft.php @@ -0,0 +1,83 @@ + 'ENGINE=InnoDB'); + + static $db = array( + 'Name' => 'Varchar', + 'Order' => 'Int', + ); + + static $has_one = array( + 'Consultant' => 'ConsultantDraft' + ); + + static $indexes = array( + 'Name_Owner' => array('type'=>'unique', 'value'=>'Name,ConsultantID') + ); + + /** + * @return void + */ + public function getOrder() + { + return (int)$this->getField('Order'); + } + + /** + * @param int $order + * @return void + */ + public function setOrder($order) + { + $this->setField('Order',$order); + } + + /** + * @return string + */ + public function getName() + { + return $this->getField('Name'); + } + + /** + * @param string $name + * @return void + */ + public function setName($name) + { + $this->setField('Name',$name); + } + + /** + * @return IConsultant + */ + public function getConsultant() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Consultant','PreviousClients')->getTarget(); + } + + /** + * @param IConsultant $consultant + * @return void + */ + public function setConsultant(IConsultant $consultant) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'Consultant','PreviousClients')->setTarget($consultant); + } + + /** + * @return int + */ + public function getIdentifier() + { + return (int)$this->getField('ID'); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/consultants/ConsultantDraft.php b/marketplace/code/infrastructure/active_records/consultants/ConsultantDraft.php new file mode 100644 index 0000000..55bea19 --- /dev/null +++ b/marketplace/code/infrastructure/active_records/consultants/ConsultantDraft.php @@ -0,0 +1,211 @@ + 'ENGINE=InnoDB'); + + static $has_many = array( + 'Offices' => 'OfficeDraft', + 'PreviousClients' => 'ConsultantClientDraft', + ); + + static $many_many = array( + 'SpokenLanguages' => 'SpokenLanguage', + 'ConfigurationManagementExpertises' => 'ConfigurationManagementType', + 'ExpertiseAreas' => 'OpenStackComponent', + 'ServicesOffered' => 'ConsultantServiceOfferedType', + ); + + static $many_many_extraFields = array( + 'ServicesOffered' => array( + 'RegionID' => "Int", + ), + 'SpokenLanguages' => array( + 'Order' => 'Int', + ), + ); + + /** + * @return IOffice[] + */ + public function getOffices() + { + $query = new QueryObject(new Office); + $query->addOrder(QueryOrder::asc('Order')); + return AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Offices',$query)->toArray(); + } + + /** + * @param IOffice $office + * @return void + */ + public function addOffice(IOffice $office) + { + $new_order = 0; + $offices = $this->getOffices(); + if(count($offices)>0){ + $last_one = end($offices); + $new_order = $last_one->getOrder()+1; + } + $office->setOrder($new_order); + $query = new QueryObject(new Office); + $query->addOrder(QueryOrder::asc('Order')); + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Offices',$query)->add($office); + } + + /** + * @return void + */ + public function clearOffices() + { + $query = new QueryObject(new Office); + $query->addOrder(QueryOrder::asc('Order')); + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'Offices',$query)->removeAll(); + } + + /** + * @return IConsultantClient[] + */ + public function getPreviousClients() + { + $query = new QueryObject(new ConsultantClient); + $query->addOrder(QueryOrder::asc('Order')); + return AssociationFactory::getInstance()->getOne2ManyAssociation($this,'PreviousClients',$query)->toArray(); + } + + /** + * @param IConsultantClient $client + * @return void + */ + public function addPreviousClients(IConsultantClient $client) + { + $new_order = 0; + $clients = $this->getPreviousClients(); + if(count($clients)>0){ + $last_one = end($clients); + $new_order = $last_one->getOrder()+1; + } + $client->setOrder($new_order); + $query = new QueryObject(new ConsultantClient()); + $query->addOrder(QueryOrder::asc('Order')); + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'PreviousClients',$query)->add($client); + } + + /** + * @return void + */ + public function clearClients() + { + $query = new QueryObject(new ConsultantClient); + $query->addOrder(QueryOrder::asc('Order')); + AssociationFactory::getInstance()->getOne2ManyAssociation($this,'PreviousClients',$query)->removeAll(); + } + + /** + * @return ISpokenLanguage[] + */ + public function getSpokenLanguages() + { + $query = new QueryObject(new SpokenLanguage); + $query->addOrder(QueryOrder::asc('Order')); + return AssociationFactory::getInstance()->getMany2ManyAssociation($this,'SpokenLanguages',$query)->toArray(); + } + + /** + * @param ISpokenLanguage $language + * @return void + */ + public function addSpokenLanguages(ISpokenLanguage $language) + { + $query = new QueryObject(new SpokenLanguage); + $query->addOrder(QueryOrder::asc('Order')); + $languages = $this->getSpokenLanguages(); + $new_order = count($languages); + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'SpokenLanguages',$query)->add($language , array('Order' => $new_order)); + } + + /** + * @return void + */ + public function clearSpokenLanguages() + { + $query = new QueryObject(new SpokenLanguage); + $query->addOrder(QueryOrder::asc('Order')); + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'SpokenLanguages',$query)->removeAll(); + } + + /** + * @return IConfigurationManagementType[] + */ + public function getConfigurationManagementExpertises() + { + return AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ConfigurationManagementExpertises')->toArray(); + } + + public function addConfigurationManagementExpertise(IConfigurationManagementType $expertise) + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ConfigurationManagementExpertises')->add($expertise); + } + + public function clearConfigurationManagementExpertises() + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ConfigurationManagementExpertises')->removeAll(); + } + + /** + * @return IOpenStackComponent[] + */ + public function getExpertiseAreas() + { + return AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ExpertiseAreas')->toArray(); + } + + /** + * @param IOpenStackComponent $component + * @return void + */ + public function addExpertiseArea(IOpenStackComponent $component) + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ExpertiseAreas')->add($component); + } + + /** + * @return void + */ + public function clearExpertiseAreas() + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ExpertiseAreas')->removeAll(); + } + + /** + * @return IConsultantServiceOfferedType[] + */ + public function getServicesOffered() + { + return AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ServicesOffered')->toArray(); + } + + /** + * @param IConsultantServiceOfferedType $service + * @param IRegion $region + * @return void + */ + public function addServiceOffered(IConsultantServiceOfferedType $service, IRegion $region) + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ServicesOffered')->add($service, array('RegionID'=>$region->getIdentifier())); + } + + /** + * @return void + */ + public function clearServicesOffered() + { + AssociationFactory::getInstance()->getMany2ManyAssociation($this,'ServicesOffered')->removeAll(); + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/active_records/consultants/OfficeDraft.php b/marketplace/code/infrastructure/active_records/consultants/OfficeDraft.php new file mode 100644 index 0000000..85fafb9 --- /dev/null +++ b/marketplace/code/infrastructure/active_records/consultants/OfficeDraft.php @@ -0,0 +1,212 @@ + 'ENGINE=InnoDB'); + + static $db = array( + 'Address' => 'Varchar', + 'Address2' => 'Varchar', + 'State' => 'Varchar', + 'ZipCode' => 'Varchar', + 'City' => 'Varchar', + 'Country' => 'Varchar', + 'Lat' => 'Decimal', + 'Lng' => 'Decimal', + 'Order' => 'Int', + ); + + static $has_one = array( + 'Consultant' => 'ConsultantDraft' + ); + + /** + * @return string + */ + public function getAddress() + { + return $this->getField('Address'); + } + + /** + * @param string $address + * @return void + */ + public function setAddress($address) + { + $this->setField('Address',$address); + } + + /** + * @return string + */ + public function getAddress1() + { + return $this->getField('Address2'); + } + + /** + * @param string $address1 + * @return void + */ + public function setAddress1($address1) + { + $this->setField('Address2',$address1); + } + + /** + * @return string + */ + public function getState() + { + return $this->getField('State'); + } + + /** + * @param string $state + * @return void + */ + public function setState($state) + { + $this->setField('State',$state); + } + + /** + * @return string + */ + public function getZipCode() + { + return $this->getField('ZipCode'); + } + + /** + * @param string $zip_code + * @return void + */ + public function setZipCode($zip_code) + { + $this->setField('ZipCode',$zip_code); + } + + /** + * @param string $country + * @return void + */ + public function setCountry($country) + { + $this->setField('Country',$country); + } + + /** + * @return string + */ + public function getCountry() + { + return $this->getField('Country'); + } + + + /** + * @param string $city + * @return void + */ + public function setCity($city) + { + $this->setField('City',$city); + } + + /** + * @return string + */ + public function getCity() + { + return $this->getField('City'); + } + + + /** + * @param float $lng + * @return void + */ + public function setLng($lng) + { + $this->setField('Lng',$lng); + } + + /** + * @return float + */ + public function getLng() + { + return $this->getField('Lng'); + } + + /** + * @param float $lat + * @return void + */ + public function setLat($lat) + { + $this->setField('Lat',$lat); + } + + /** + * @return float + */ + public function getLat() + { + return $this->getField('Lat'); + } + + + /** + * @return IConsultant + */ + public function getConsultant() + { + return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Consultant','Offices')->getTarget(); + } + + /** + * @param IConsultant $consultant + * @return void + */ + public function setConsultant(IConsultant $consultant) + { + AssociationFactory::getInstance()->getMany2OneAssociation($this,'Consultant','Offices')->setTarget($consultant); + } + + /** + * @return int + */ + public function getIdentifier() + { + return (int)$this->getField('ID'); + } + + /** + * @return void + */ + public function getOrder() + { + return (int)$this->getField('Order'); + } + + /** + * @param int $order + * @return void + */ + public function setOrder($order) + { + $this->setField('Order',$order); + } + + public function getCountryFriendlyName(){ + return Geoip::countryCode2name($this->getCountry()); + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/ApplianceDraftFactory.php b/marketplace/code/infrastructure/factories/ApplianceDraftFactory.php new file mode 100644 index 0000000..3630cc1 --- /dev/null +++ b/marketplace/code/infrastructure/factories/ApplianceDraftFactory.php @@ -0,0 +1,44 @@ +setName($name); + $appliance->setOverview($overview); + $appliance->setCompany($company); + if($active) + $appliance->activate(); + else + $appliance->deactivate(); + $appliance->setMarketplace($marketplace_type); + $appliance->setCall2ActionUri($call_2_action_url); + $appliance->setLiveServiceId($live_id); + return $appliance; + } + + /** + * @param $id + * @return ICompanyService + */ + public function buildCompanyServiceById($id) + { + $appliance = new ApplianceDraft; + $appliance->ID = $id; + return $appliance; + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/CloudDraftFactory.php b/marketplace/code/infrastructure/factories/CloudDraftFactory.php new file mode 100644 index 0000000..aab4225 --- /dev/null +++ b/marketplace/code/infrastructure/factories/CloudDraftFactory.php @@ -0,0 +1,82 @@ +setCoveragePercent($coverage_percent); + $service->setReleaseSupportedApiVersion($release_supported_api_version); + $service->setImplementation($implementation); + return $service; + } + + /** + * @param $id + * @return IPricingSchemaType + */ + public function buildPricingSchemaById($id){ + $pricing_schema = new PricingSchemaType; + $pricing_schema->ID = $id; + return $pricing_schema; + } + + /** + * @param string $city + * @param string $state + * @param string $country + * @param float $lat + * @param float $lng + * @param IDataCenterRegion $region + * @return IDataCenterLocation + */ + public function buildDataCenterLocation($city,$state,$country,$lat,$lng,IDataCenterRegion $region) { + $location = new DataCenterLocationDraft; + $location->setCity($city); + $location->setState($state); + $location->setCountry($country); + $location->setLat($lat); + $location->setLng($lng); + $region->addLocation($location); + $location->setDataCenterRegion($region); + return $location; + } + + /** + * @param $name + * @param IDataCenterLocation $location + * @return IAvailabilityZone + */ + public function buildAZ($name,IDataCenterLocation $location){ + $az = new AvailabilityZoneDraft; + $az->setName($name); + $az->setLocation($location); + $location->addAvailabilityZone($az); + return $az; + } + + /** + * @param string $name + * @param string $color + * @param string $endpoint + * @return IDataCenterRegion + */ + public function buildDataCenterRegion($name, $color, $endpoint) + { + $region = new DataCenterRegionDraft; + $region->setName($name); + $region->setColor($color); + $region->setEndpoint($endpoint); + return $region; + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/ConsultantDraftFactory.php b/marketplace/code/infrastructure/factories/ConsultantDraftFactory.php new file mode 100644 index 0000000..f07db6d --- /dev/null +++ b/marketplace/code/infrastructure/factories/ConsultantDraftFactory.php @@ -0,0 +1,91 @@ +setName($name); + $consultant->setOverview($overview); + $consultant->setCompany($company); + if($active) + $consultant->activate(); + else + $consultant->deactivate(); + $consultant->setMarketplace($marketplace_type); + $consultant->setCall2ActionUri($call_2_action_url); + $consultant->setLiveServiceId($live_id); + return $consultant; + } + + /** + * @param $id + * @return ICompanyService + */ + public function buildCompanyServiceById($id) + { + $consultant = new ConsultantDraft; + $consultant->ID = $id; + return $consultant; + } + + /** + * @param string $name + * @return ISpokenLanguage + */ + public function buildSpokenLanguage($name) + { + $language = new SpokenLanguage; + $language->setName($name); + return $language; + } + + /** + * @param string $type + * @return IConfigurationManagementType + */ + public function buildConfigurationManagementType($type) + { + $config_management = new ConfigurationManagementType; + $config_management->setType($type); + return $config_management; + } + + /** + * @param string $name + * @return IConsultantClient + */ + public function buildClient($name) + { + $client = new ConsultantClientDraft; + $client->setName($name); + return $client; + } + + public function buildOffice(AddressInfo $address_info) + { + $office = new OfficeDraft; + list($address1,$address2)=$address_info->getAddress(); + $office->setAddress($address1); + $office->setAddress1($address2); + $office->setZipCode($address_info->getZipCode()); + $office->setCity($address_info->getCity()); + $office->setState($address_info->getState()); + $office->setCountry($address_info->getCountry()); + return $office; + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/ConsultantFactory.php b/marketplace/code/infrastructure/factories/ConsultantFactory.php index 37a0420..6a34467 100644 --- a/marketplace/code/infrastructure/factories/ConsultantFactory.php +++ b/marketplace/code/infrastructure/factories/ConsultantFactory.php @@ -27,7 +27,7 @@ final class ConsultantFactory * @param null|string $call_2_action_url * @return ICompanyService */ - public function buildCompanyService($name, $overview, ICompany $company, $active, IMarketPlaceType $marketplace_type, $call_2_action_url = null, $live_service = null) + public function buildCompanyService($name, $overview, ICompany $company, $active, IMarketPlaceType $marketplace_type, $call_2_action_url = null, $live_id = null) { $consultant = new Consultant; $consultant->setName($name); @@ -39,6 +39,7 @@ final class ConsultantFactory $consultant->deactivate(); $consultant->setMarketplace($marketplace_type); $consultant->setCall2ActionUri($call_2_action_url); + $consultant->setLiveServiceId($live_id); return $consultant; } diff --git a/marketplace/code/infrastructure/factories/DistributionDraftFactory.php b/marketplace/code/infrastructure/factories/DistributionDraftFactory.php index adf353b..93182bf 100644 --- a/marketplace/code/infrastructure/factories/DistributionDraftFactory.php +++ b/marketplace/code/infrastructure/factories/DistributionDraftFactory.php @@ -3,7 +3,7 @@ /** * Class DistributionDraftFactory */ -final class DistributionDraftFactory extends OpenStackImplementationFactory { +final class DistributionDraftFactory extends OpenStackImplementationDraftFactory { /** * @param string $name @@ -41,30 +41,4 @@ final class DistributionDraftFactory extends OpenStackImplementationFactory { return $distribution; } - /** - * @param IRegion $region - * @param IRegionalSupportedCompanyService $service - * @return IRegionalSupport - */ - public function buildRegionalSupport(IRegion $region, IRegionalSupportedCompanyService $service){ - $regional_support = new RegionalSupportDraft; - $regional_support->setRegion($region); - $regional_support->setCompanyService($service); - return $regional_support; - } - - /** - * @param int $coverage_percent - * @param IReleaseSupportedApiVersion $release_supported_api_version - * @param IOpenStackImplementation $implementation - * @return IOpenStackImplementationApiCoverage - */ - public function buildCapability($coverage_percent, IReleaseSupportedApiVersion $release_supported_api_version, IOpenStackImplementation $implementation) - { - $capability = new OpenStackImplementationApiCoverageDraft; - $capability->setCoveragePercent($coverage_percent); - $capability->setReleaseSupportedApiVersion($release_supported_api_version); - $capability->setImplementation($implementation); - return $capability; - } } \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/MarketplaceDraftFactory.php b/marketplace/code/infrastructure/factories/MarketplaceDraftFactory.php new file mode 100644 index 0000000..f2d9c4c --- /dev/null +++ b/marketplace/code/infrastructure/factories/MarketplaceDraftFactory.php @@ -0,0 +1,125 @@ +setName($name); + $marketplace_type->activate(); + $slug = str_replace(' ', '-', strtolower($name)); + $marketplace_type->setSlug($slug); + $g = $marketplace_type->createSecurityGroup(); + $marketplace_type->setAdminGroup($g); + return $marketplace_type; + } + + /** + * @param string $title + * @return ISecurityGroup + */ + public function buildSecurityGroup($title) + { + $g = new Group; + $g->setTitle($title); + $g->setDescription($title); + $g->setSlug(str_replace(' ', '-', strtolower($title))); + return $g; + } + + /** + * @param string $type + * @param int $max_allowed_duration + * @return IMarketPlaceVideoType + */ + public function buildMarketPlaceVideoType($type, $max_allowed_duration) + { + $video_type = new MarketPlaceVideoType; + $video_type->Type = $type; + $video_type->MaxTotalVideoTime = $max_allowed_duration; + return $video_type; + } + + public function buildVideoTypeById($id){ + $video_type = new MarketPlaceVideoType; + $video_type->ID = $id; + return $video_type; + } + + /*** + * @param int $id + * @return ICompany + */ + public function buildCompanyById($id) + { + $company = new Company; + $company->ID = $id; + return $company; + } + + /** + * @param string $name + * @param string $uri + * @param ICompanyService $company_service + * @return ICompanyServiceResource + */ + public function buildResource($name, $uri, ICompanyService $company_service) + { + $resource = new CompanyServiceResourceDraft; + $resource->setName($name); + $resource->setUri($uri); + $resource->setOwner($company_service); + return $resource; + } + + + /** + * @param string $name + * @param string $description + * @param string $youtube_id + * @param int $length + * @param IMarketPlaceVideoType $type + * @param ICompanyService $owner + * @return IMarketPlaceVideo + */ + public function buildVideo($name, $description, $youtube_id, $length, IMarketPlaceVideoType $type, ICompanyService $owner) + { + $video = new MarketPlaceVideoDraft; + $video->setName($name); + $video->setDescription($description); + $video->setYouTubeId($youtube_id); + $video->setLength($length); + $video->setType($type); + $video->setOwner($owner); + return $video; + } + + /** + * @param int $region_id + * @return IRegion + */ + public function buildRegionById($region_id) + { + $region = new Region; + $region->ID = $region_id; + return $region; + } + + /** + * @param int $support_channel_type_id + * @return ISupportChannelType + */ + public function buildSupportChannelTypeById($support_channel_type_id) + { + $support_channel_type = new SupportChannelType; + $support_channel_type->ID = $support_channel_type_id; + return $support_channel_type; + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/OpenStackImplementationDraftFactory.php b/marketplace/code/infrastructure/factories/OpenStackImplementationDraftFactory.php new file mode 100644 index 0000000..d1a022f --- /dev/null +++ b/marketplace/code/infrastructure/factories/OpenStackImplementationDraftFactory.php @@ -0,0 +1,22 @@ +setCoveragePercent($coverage_percent); + $capability->setReleaseSupportedApiVersion($release_supported_api_version); + $capability->setImplementation($implementation); + return $capability; + } + + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/PrivateCloudDraftFactory.php b/marketplace/code/infrastructure/factories/PrivateCloudDraftFactory.php new file mode 100644 index 0000000..bbfe175 --- /dev/null +++ b/marketplace/code/infrastructure/factories/PrivateCloudDraftFactory.php @@ -0,0 +1,42 @@ +setName($name); + $private_cloud->setOverview($overview); + $private_cloud->setCompany($company); + if($active) + $private_cloud->activate(); + else + $private_cloud->deactivate(); + $private_cloud->setMarketplace($marketplace_type); + $private_cloud->setCall2ActionUri($call_2_action_url); + $private_cloud->setLiveServiceId($live_id); + return $private_cloud; + } + + /** + * @param $id + * @return ICompanyService + */ + public function buildCompanyServiceById($id) + { + $private_cloud = new PrivateCloudServiceDraft; + $private_cloud->ID = $id; + return $private_cloud; + } +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/PublicCloudDraftFactory.php b/marketplace/code/infrastructure/factories/PublicCloudDraftFactory.php new file mode 100644 index 0000000..3d27430 --- /dev/null +++ b/marketplace/code/infrastructure/factories/PublicCloudDraftFactory.php @@ -0,0 +1,45 @@ +setName($name); + $public_cloud->setOverview($overview); + $public_cloud->setCompany($company); + if($active) + $public_cloud->activate(); + else + $public_cloud->deactivate(); + $public_cloud->setMarketplace($marketplace_type); + $public_cloud->setCall2ActionUri($call_2_action_url); + $public_cloud->setLiveServiceId($live_id); + return $public_cloud; + } + + /** + * @param $id + * @return ICompanyService + */ + public function buildCompanyServiceById($id) + { + $public_cloud = new PublicCloudServiceDraft(); + $public_cloud->ID = $id; + return $public_cloud; + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/factories/RegionalSupportedCompanyServiceDraftFactory.php b/marketplace/code/infrastructure/factories/RegionalSupportedCompanyServiceDraftFactory.php new file mode 100644 index 0000000..dd215b6 --- /dev/null +++ b/marketplace/code/infrastructure/factories/RegionalSupportedCompanyServiceDraftFactory.php @@ -0,0 +1,16 @@ +setRegion($region); + $regional_support->setCompanyService($service); + return $regional_support; + } + +} \ No newline at end of file diff --git a/marketplace/code/infrastructure/repositories/SapphirePrivateCloudRepository.php b/marketplace/code/infrastructure/repositories/SapphirePrivateCloudRepository.php index ad28e9b..978e38a 100644 --- a/marketplace/code/infrastructure/repositories/SapphirePrivateCloudRepository.php +++ b/marketplace/code/infrastructure/repositories/SapphirePrivateCloudRepository.php @@ -18,7 +18,7 @@ final class SapphirePrivateCloudRepository extends SapphireOpenStackImplementationRepository { public function __construct($draft_entity=false){ - $entity = ($draft_entity) ? new PrivateCloudServiceDraft() : new PublicCloudService(); + $entity = ($draft_entity) ? new PrivateCloudServiceDraft() : new PrivateCloudService(); parent::__construct($entity); } diff --git a/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php index 64871b8..3af1fcb 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php @@ -18,11 +18,13 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { private $marketplace_type_repository; private $appliance_repository; + private $appliance_draft_repository; public function __construct() { $this->appliance_repository = new SapphireApplianceRepository; + $this->appliance_draft_repository = new SapphireApplianceRepository(true); $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; $manager = new ApplianceManager ( @@ -49,12 +51,36 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { SapphireTransactionManager::getInstance() ); - parent::__construct($manager, new ApplianceFactory); + $draft_manager = new ApplianceManager ( + $this->appliance_draft_repository, + new SapphireMarketPlaceVideoTypeRepository, + $this->marketplace_type_repository, + new SapphireGuestOSTypeRepository, + new SapphireHyperVisorTypeRepository, + new SapphireOpenStackApiVersionRepository, + new SapphireOpenStackComponentRepository, + new SapphireOpenStackReleaseRepository, + new SapphireRegionRepository, + new SapphireSupportChannelTypeRepository, + new SapphireOpenStackReleaseSupportedApiVersionRepository, + new ApplianceAddPolicy($this->appliance_draft_repository, $this->marketplace_type_repository), + new CompanyServiceCanAddResourcePolicy, + new CompanyServiceCanAddVideoPolicy, + new ApplianceDraftFactory, + new MarketplaceDraftFactory, + new ValidatorFactory, + new OpenStackApiFactory, + null, + new SessionCacheService, + SapphireTransactionManager::getInstance() + ); + + parent::__construct($manager, $draft_manager, new ApplianceFactory, new ApplianceDraftFactory); // filters ... $this_var = $this; $current_user = $this->current_user; - $repository = $this->appliance_repository; + $repository = $this->appliance_draft_repository; $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user,$repository){ $data = $this_var->getJsonRequest(); @@ -90,6 +116,7 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', + 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', ); /** @@ -99,7 +126,8 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { 'getDistribution', 'deleteCompanyService', 'addCompanyService', - 'updateCompanyService' + 'updateCompanyService', + 'publishCompanyService' ); public function getDistribution(){ @@ -110,9 +138,17 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { return $this->ok(OpenStackImplementationAssembler::convertOpenStackImplementationToArray($appliance)); } + public function getDistributionDraft(){ + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $appliance = $this->appliance_draft_repository->getByLiveServiceId($company_service_id); + if(!$appliance) + return $this->notFound(); + return $this->ok(OpenStackImplementationAssembler::convertOpenStackImplementationToArray($appliance)); + } + public function addCompanyService(){ try { - return parent::addCompanyService(); + return parent::addCompanyServiceDraft(); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); @@ -122,7 +158,7 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { public function updateCompanyService(){ try { - return parent::updateCompanyService(); + return parent::updateCompanyServiceDraft(); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); @@ -130,4 +166,25 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { } } + public function publishCompanyService(){ + try { + return parent::publishCompanyService(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function deleteCompanyService(){ + try { + parent::deleteCompanyService(); + return parent::deleteCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + } \ No newline at end of file diff --git a/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php index 372b1a4..a900575 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php @@ -16,33 +16,35 @@ */ final class ConsultantsCrudApi extends CompanyServiceCrudApi { - /** * @var array */ - private static $url_handlers = array( + static $url_handlers = array( 'GET languages' => 'getLanguages', 'GET $COMPANY_SERVICE_ID!' => 'getConsultant', 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', + 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', ); /** * @var array */ - private static $allowed_actions = array( + static $allowed_actions = array( 'getConsultant', 'deleteCompanyService', 'addCompanyService', 'updateCompanyService', - 'getLanguages' + 'getLanguages', + 'publishCompanyService' ); /** * @var IEntityRepository */ private $consultant_repository; + private $consultant_draft_repository; /** * @var IEntityRepository */ @@ -50,9 +52,10 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { public function __construct(){ - $this->consultant_repository = new SapphireConsultantRepository; - $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; - $this->languages_repository = new SapphireSpokenLanguageRepository; + $this->consultant_repository = new SapphireConsultantRepository; + $this->consultant_draft_repository = new SapphireConsultantRepository(true); + $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; + $this->languages_repository = new SapphireSpokenLanguageRepository; $google_geo_coding_api_key = null; $google_geo_coding_client_id = null; $google_geo_coding_private_key = null; @@ -95,7 +98,38 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { SapphireTransactionManager::getInstance() ); - parent::__construct($manager,new ConsultantFactory); + $draft_manager = new ConsultantManager ( + $this->consultant_draft_repository, + new SapphireMarketPlaceVideoTypeRepository, + $this->marketplace_type_repository, + new SapphireOpenStackApiVersionRepository, + new SapphireOpenStackComponentRepository, + new SapphireOpenStackReleaseRepository, + new SapphireRegionRepository, + new SapphireSupportChannelTypeRepository, + $this->languages_repository, + new SapphireConfigurationManagementTypeRepository, + new SapphireConsultantServiceOfferedTypeRepository, + new ConsultantAddPolicy($this->consultant_draft_repository, $this->marketplace_type_repository), + new CompanyServiceCanAddResourcePolicy, + new CompanyServiceCanAddVideoPolicy, + new ConsultantDraftFactory, + new MarketplaceDraftFactory, + new ValidatorFactory, + new OpenStackApiFactory, + new GoogleGeoCodingService( + new SapphireGeoCodingQueryRepository, + new UtilFactory, + SapphireTransactionManager::getInstance(), + $google_geo_coding_api_key, + $google_geo_coding_client_id, + $google_geo_coding_private_key), + null, + new SessionCacheService, + SapphireTransactionManager::getInstance() + ); + + parent::__construct($manager,$draft_manager,new ConsultantFactory,new ConsultantDraftFactory); // filters ... $this_var = $this; @@ -133,6 +167,14 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { return $this->ok(ConsultantAssembler::convertConsultantToArray($consultant)); } + public function getConsultantDraft(){ + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $consultant = $this->consultant_draft_repository->getByLiveServiceId($company_service_id); + if(!$consultant) + return $this->notFound(); + return $this->ok(OpenStackImplementationAssembler::convertOpenStackImplementationToArray($consultant)); + } + public function getLanguages(){ $term = Convert::raw2sql ($this->request->getVar('term')); $query = new QueryObject; @@ -144,4 +186,46 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { } return $this->ok($res); } + + public function addCompanyService(){ + try { + return parent::addCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function updateCompanyService(){ + try { + return parent::updateCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function publishCompanyService(){ + try { + return parent::publishCompanyService(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function deleteCompanyService(){ + try { + parent::deleteCompanyService(); + return parent::deleteCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + } \ No newline at end of file diff --git a/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php index dc2a013..a325978 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php @@ -67,7 +67,7 @@ final class DistributionCrudApi extends CompanyServiceCrudApi { new CompanyServiceCanAddResourcePolicy, new CompanyServiceCanAddVideoPolicy, new DistributionDraftFactory, - new MarketplaceFactory, + new MarketplaceDraftFactory, new ValidatorFactory, new OpenStackApiFactory, null, diff --git a/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php index 5e0abb7..d4d98ea 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php @@ -18,11 +18,13 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { private $marketplace_type_repository; private $private_cloud_repository; + private $private_cloud_draft_repository; public function __construct(){ - $this->private_cloud_repository = new SapphirePrivateCloudRepository; - $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; + $this->private_cloud_repository = new SapphirePrivateCloudRepository; + $this->private_cloud_draft_repository = new SapphirePrivateCloudRepository(true); + $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; //google geo coding settings $google_geo_coding_api_key = null; @@ -67,7 +69,38 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { SapphireTransactionManager::getInstance() ); - parent::__construct($manager,new PublicCloudFactory); + $draft_manager = new PrivateCloudManager ( + $this->private_cloud_draft_repository, + new SapphireMarketPlaceVideoTypeRepository, + $this->marketplace_type_repository, + new SapphireGuestOSTypeRepository, + new SapphireHyperVisorTypeRepository, + new SapphireOpenStackApiVersionRepository, + new SapphireOpenStackComponentRepository, + new SapphireOpenStackReleaseRepository, + new SapphireRegionRepository, + new SapphireSupportChannelTypeRepository, + new SapphireOpenStackReleaseSupportedApiVersionRepository, + new PrivateCloudAddPolicy($this->private_cloud_draft_repository, $this->marketplace_type_repository), + new CompanyServiceCanAddResourcePolicy, + new CompanyServiceCanAddVideoPolicy, + new PrivateCloudDraftFactory, + new MarketplaceDraftFactory, + new ValidatorFactory, + new OpenStackApiFactory, + new GoogleGeoCodingService( + new SapphireGeoCodingQueryRepository, + new UtilFactory, + SapphireTransactionManager::getInstance(), + $google_geo_coding_api_key, + $google_geo_coding_client_id, + $google_geo_coding_private_key), + null, + new SessionCacheService, + SapphireTransactionManager::getInstance() + ); + + parent::__construct($manager,$draft_manager,new PublicCloudFactory,new PublicCloudDraftFactory); // filters ... $this_var = $this; @@ -106,6 +139,7 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', + 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', ); /** @@ -115,7 +149,8 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { 'getPrivateCloud', 'deleteCompanyService', 'addCompanyService', - 'updateCompanyService' + 'updateCompanyService', + 'publishCompanyService' ); public function getPrivateCloud(){ @@ -126,9 +161,17 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { return $this->ok(CloudAssembler::convertCloudToArray($private_cloud)); } + public function getPrivateCloudDraft(){ + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $private_cloud = $this->private_cloud_draft_repository->getByLiveServiceId($company_service_id); + if(!$private_cloud) + return $this->notFound(); + return $this->ok(OpenStackImplementationAssembler::convertOpenStackImplementationToArray($private_cloud)); + } + public function addCompanyService(){ try { - return parent::addCompanyService(); + return parent::addCompanyServiceDraft(); } catch (NonSupportedApiVersion $ex1) { SS_Log::log($ex1,SS_Log::ERR); @@ -146,7 +189,7 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { public function updateCompanyService(){ try { - return parent::updateCompanyService(); + return parent::updateCompanyServiceDraft(); } catch (NonSupportedApiVersion $ex1) { SS_Log::log($ex1,SS_Log::ERR); @@ -161,4 +204,25 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { return $this->serverError(); } } + + public function publishCompanyService(){ + try { + return parent::publishCompanyService(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function deleteCompanyService(){ + try { + parent::deleteCompanyService(); + return parent::deleteCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } } \ No newline at end of file diff --git a/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php index 2304eb3..b8282b7 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php @@ -18,11 +18,13 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { private $marketplace_type_repository; private $public_cloud_repository; + private $public_cloud_draft_repository; public function __construct(){ - $this->public_cloud_repository = new SapphirePublicCloudRepository; - $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; + $this->public_cloud_repository = new SapphirePublicCloudRepository; + $this->public_cloud_draft_repository = new SapphirePublicCloudRepository(true); + $this->marketplace_type_repository = new SapphireMarketPlaceTypeRepository; //google geo coding settings $google_geo_coding_api_key = null; @@ -67,7 +69,38 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { SapphireTransactionManager::getInstance() ); - parent::__construct($manager,new PublicCloudFactory); + $draft_manager = new PublicCloudManager ( + $this->public_cloud_draft_repository, + new SapphireMarketPlaceVideoTypeRepository, + $this->marketplace_type_repository, + new SapphireGuestOSTypeRepository, + new SapphireHyperVisorTypeRepository, + new SapphireOpenStackApiVersionRepository, + new SapphireOpenStackComponentRepository, + new SapphireOpenStackReleaseRepository, + new SapphireRegionRepository, + new SapphireSupportChannelTypeRepository, + new SapphireOpenStackReleaseSupportedApiVersionRepository, + new PublicCloudAddPolicy($this->public_cloud_draft_repository, $this->marketplace_type_repository), + new CompanyServiceCanAddResourcePolicy, + new CompanyServiceCanAddVideoPolicy, + new PublicCloudDraftFactory, + new MarketplaceDraftFactory, + new ValidatorFactory, + new OpenStackApiFactory, + new GoogleGeoCodingService( + new SapphireGeoCodingQueryRepository, + new UtilFactory, + SapphireTransactionManager::getInstance(), + $google_geo_coding_api_key, + $google_geo_coding_client_id, + $google_geo_coding_private_key), + null, + new SessionCacheService, + SapphireTransactionManager::getInstance() + ); + + parent::__construct($manager,$draft_manager,new PublicCloudFactory,new PublicCloudDraftFactory); // filters ... $this_var = $this; @@ -106,6 +139,7 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', + 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', ); /** @@ -115,7 +149,8 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { 'getPublicCloud', 'deleteCompanyService', 'addCompanyService', - 'updateCompanyService' + 'updateCompanyService', + 'publishCompanyService' ); public function getPublicCloud(){ @@ -126,9 +161,17 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { return $this->ok(CloudAssembler::convertCloudToArray($public_cloud)); } + public function getPublicCloudDraft(){ + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $public_cloud = $this->public_cloud_draft_repository->getByLiveServiceId($company_service_id); + if(!$public_cloud) + return $this->notFound(); + return $this->ok(OpenStackImplementationAssembler::convertOpenStackImplementationToArray($public_cloud)); + } + public function addCompanyService(){ try { - return parent::addCompanyService(); + return parent::addCompanyServiceDraft(); } catch (NonSupportedApiVersion $ex1) { SS_Log::log($ex1,SS_Log::ERR); @@ -146,7 +189,7 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { public function updateCompanyService(){ try { - return parent::updateCompanyService(); + return parent::updateCompanyServiceDraft(); } catch (NonSupportedApiVersion $ex1) { SS_Log::log($ex1,SS_Log::ERR); @@ -161,4 +204,25 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { return $this->serverError(); } } + + public function publishCompanyService(){ + try { + return parent::publishCompanyService(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } + + public function deleteCompanyService(){ + try { + parent::deleteCompanyService(); + return parent::deleteCompanyServiceDraft(); + } + catch (Exception $ex) { + SS_Log::log($ex,SS_Log::ERR); + return $this->serverError(); + } + } } \ No newline at end of file diff --git a/marketplace/code/ui/admin/MarketPlaceAdminPage.php b/marketplace/code/ui/admin/MarketPlaceAdminPage.php index 48201d3..7725e45 100644 --- a/marketplace/code/ui/admin/MarketPlaceAdminPage.php +++ b/marketplace/code/ui/admin/MarketPlaceAdminPage.php @@ -51,11 +51,14 @@ class MarketPlaceAdminPage_Controller extends Page_Controller * @var ICompanyServiceRepository */ private $distribution_draft_repository; - /** * @var ICompanyServiceRepository */ private $appliance_repository; + /** + * @var ICompanyServiceRepository + */ + private $appliance_draft_repository; /** * @var IOpenStackComponentRepository */ @@ -68,7 +71,6 @@ class MarketPlaceAdminPage_Controller extends Page_Controller * @var IEntityRepository */ private $guests_os_repository; - /** * @var IEntityRepository */ @@ -85,31 +87,38 @@ class MarketPlaceAdminPage_Controller extends Page_Controller * @var IEntityRepository */ private $pricing_schema_repository; - /** * @var IEntityRepository */ private $public_clouds_repository; - + /** + * @var IEntityRepository + */ + private $public_clouds_draft_repository; /** * @var IEntityRepository */ private $private_clouds_repository; - + /** + * @var IEntityRepository + */ + private $private_clouds_draft_repository; /** * @var IEntityRepository */ private $config_management_type_repository; - /** * @var IEntityRepository */ private $consultant_service_offered_type_repository; - /** * @var IEntityRepository */ private $consultant_repository; + /** + * @var IEntityRepository + */ + private $consultant_draft_repository; function init() { @@ -146,6 +155,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $this->distribution_repository = new SapphireDistributionRepository; $this->distribution_draft_repository = new SapphireDistributionRepository(true); $this->appliance_repository = new SapphireApplianceRepository; + $this->appliance_draft_repository = new SapphireApplianceRepository(true); $this->components_repository = new SapphireOpenStackComponentRepository; $this->hyper_visors_repository = new SapphireHyperVisorTypeRepository; $this->guests_os_repository = new SapphireGuestOSTypeRepository(); @@ -154,10 +164,13 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $this->region_repository = new SapphireRegionRepository; $this->pricing_schema_repository = new SapphirePricingSchemaRepository; $this->public_clouds_repository = new SapphirePublicCloudRepository; + $this->public_clouds_draft_repository = new SapphirePublicCloudRepository(true); $this->private_clouds_repository = new SapphirePrivateCloudRepository; + $this->private_clouds_draft_repository = new SapphirePrivateCloudRepository(true); $this->config_management_type_repository = new SapphireConfigurationManagementTypeRepository; $this->consultant_service_offered_type_repository = new SapphireConsultantServiceOfferedTypeRepository; $this->consultant_repository = new SapphireConsultantRepository; + $this->consultant_draft_repository = new SapphireConsultantRepository(true); } @@ -194,6 +207,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller 'preview', 'draft_preview', 'pdf', + 'draft_pdf', ); @@ -204,6 +218,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller 'GET $MARKETPLACETYPE/$ID/preview' => 'preview', 'GET $MARKETPLACETYPE/$ID/draft_preview' => 'draft_preview', 'GET $MARKETPLACETYPE/$ID/pdf' => 'pdf', + 'GET $MARKETPLACETYPE/$ID/draft_pdf' => 'draft_pdf', ); public function getCurrentTab() @@ -301,10 +316,15 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentAppliance() { $appliance_id = intval($this->request->getVar('id')); + $appliance = false; if ($appliance_id > 0) { - return $this->appliance_repository->getById($appliance_id); + $appliance = $this->appliance_draft_repository->getByLiveServiceId($appliance_id); + //if no draft found we pull the live one to create the draft from it when saved + if (!$appliance) { + $appliance = $this->appliance_repository->getById($appliance_id); + } } - return false; + return $appliance; } public function getOpenStackAvailableComponents() @@ -583,10 +603,15 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentConsultant() { $consultant_id = intval($this->request->getVar('id')); - if ($consultant_id > 0) { - return $this->consultant_repository->getById($consultant_id); - } - return false; + $consultant = false; + if ($consultant_id > 0) { + $consultant = $this->consultant_draft_repository->getByLiveServiceId($consultant_id); + //if no draft found we pull the live one to create the draft from it when saved + if (!$consultant) { + $consultant = $this->consultant_repository->getById($consultant_id); + } + } + return $consultant; } public function getCurrentConsultantJson() @@ -779,10 +804,15 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentPublicCloud() { $public_cloud_id = intval($this->request->getVar('id')); - if ($public_cloud_id > 0) { - return $this->public_clouds_repository->getById($public_cloud_id); - } - return false; + $public_cloud = false; + if ($public_cloud_id > 0) { + $public_cloud = $this->public_clouds_draft_repository->getByLiveServiceId($public_cloud_id); + //if no draft found we pull the live one to create the draft from it when saved + if (!$public_cloud) { + $public_cloud = $this->public_clouds_repository->getById($public_cloud_id); + } + } + return $public_cloud; } public function getCurrentPublicCloudJson() @@ -871,10 +901,15 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentPrivateCloud() { $private_cloud_id = intval($this->request->getVar('id')); - if ($private_cloud_id > 0) { - return $this->private_clouds_repository->getById($private_cloud_id); - } - return false; + $private_cloud = false; + if ($private_cloud_id > 0) { + $private_cloud = $this->private_clouds_draft_repository->getByLiveServiceId($private_cloud_id); + //if no draft found we pull the live one to create the draft from it when saved + if (!$private_cloud) { + $private_cloud = $this->private_clouds_repository->getById($private_cloud_id); + } + } + return $private_cloud; } public function getCurrentPrivateCloudJson() @@ -939,7 +974,6 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function preview() { - $marketplace_type = $this->request->param('MARKETPLACETYPE'); $instance_id = intval($this->request->param('ID')); @@ -1017,32 +1051,35 @@ class MarketPlaceAdminPage_Controller extends Page_Controller } break; case 'appliance': { - $appliance = $this->appliance_repository->getBy($query); + $appliance = $this->appliance_draft_repository->getBy($query); $appliance->IsPreview = true; $render = new ApplianceSapphireRender($appliance); return $render->draw(); } break; case 'public_cloud': { - $public_cloud = $this->public_clouds_repository->getBy($query); + $public_cloud = $this->public_clouds_draft_repository->getBy($query); $public_cloud->IsPreview = true; + $public_cloud->IsDraft = true; if (!$public_cloud) throw new NotFoundEntityException('', ''); $render = new PublicCloudSapphireRender($public_cloud); return $render->draw(); } break; case 'private_cloud': { - $private_cloud = $this->private_clouds_repository->getBy($query); + $private_cloud = $this->private_clouds_draft_repository->getBy($query); $private_cloud->IsPreview = true; + $private_cloud->IsDraft = true; $render = new PrivateCloudSapphireRender($private_cloud); return $render->draw(); } break; case 'consultant': { - $consultant = $this->consultant_repository->getBy($query); + $consultant = $this->consultant_draft_repository->getBy($query); if (!$consultant) throw new NotFoundEntityException('', ''); $consultant->IsPreview = true; + $consultant->IsDraft = true; $render = new ConsultantSapphireRender($consultant); return $render->draw(); } @@ -1075,6 +1112,28 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return CloudViewModel::getDataCenterLocationsJson($cloud); } + public function getCurrentDataCenterLocationsDraftJson() + { + $instance_id = intval($this->request->param('ID')); + $marketplace_type = $this->request->param('MARKETPLACETYPE'); + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + switch (strtolower($marketplace_type)) { + case 'public_cloud': { + $cloud = $this->public_clouds_draft_repository->getBy($query); + } + break; + case 'private_cloud': { + $cloud = $this->private_clouds_draft_repository->getBy($query); + } + break; + + } + + if (!$cloud) throw new NotFoundEntityException('', ''); + return CloudViewModel::getDataCenterLocationsJson($cloud); + } + public function getCurrentDataCenterStaticMapForPDF() { $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=1&size=300x200&maptype=roadmap"; @@ -1104,6 +1163,35 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return $static_map_url; } + public function getCurrentDataCenterStaticMapDraftForPDF() + { + $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=1&size=300x200&maptype=roadmap"; + $instance_id = intval($this->request->param('ID')); + $marketplace_type = $this->request->param('MARKETPLACETYPE'); + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + switch (strtolower($marketplace_type)) { + case 'public_cloud': { + $cloud = $this->public_clouds_draft_repository->getBy($query); + } + break; + case 'private_cloud': { + $cloud = $this->private_clouds_draft_repository->getBy($query); + } + break; + + } + + if (!$cloud) throw new NotFoundEntityException('', ''); + $locations = json_decode(CloudViewModel::getDataCenterLocationsJson($cloud)); + + foreach ($locations as $loc) { + $static_map_url .= "&markers=".$loc->lat.",".$loc->lng; + } + + return $static_map_url; + } + public function getPricingSchemas() { return CloudViewModel::getPricingSchemas(); @@ -1126,7 +1214,45 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return $pricing_schemas; } - public function getEnabledPricingSchemas() + public function getPricingSchemasDraftForPDF() + { + $pricing_schemas = CloudViewModel::getPricingSchemas(); + $enabled_ps = json_decode($this->getEnabledPricingSchemasDraft()); + + foreach($pricing_schemas as $ps) { + $ps->Enabled = 0; + foreach ($enabled_ps as $eps) { + if ($ps->ID == $eps) { + $ps->Enabled = 1; + } + } + } + + return $pricing_schemas; + } + + public function getEnabledPricingSchemas() + { + $instance_id = intval($this->request->param('ID')); + $marketplace_type = $this->request->param('MARKETPLACETYPE'); + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + switch (strtolower($marketplace_type)) { + case 'public_cloud': { + $cloud = $this->public_clouds_repository->getBy($query); + } + break; + case 'private_cloud': { + $cloud = $this->private_clouds_repository->getBy($query); + } + break; + + } + if (!$cloud) throw new NotFoundEntityException('', ''); + return CloudViewModel::getEnabledPricingSchemas($cloud); + } + + public function getEnabledPricingSchemasDraft() { $instance_id = intval($this->request->param('ID')); $marketplace_type = $this->request->param('MARKETPLACETYPE'); @@ -1134,11 +1260,11 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); switch (strtolower($marketplace_type)) { case 'public_cloud': { - $cloud = $this->public_clouds_repository->getBy($query); + $cloud = $this->public_clouds_draft_repository->getBy($query); } break; case 'private_cloud': { - $cloud = $this->private_clouds_repository->getBy($query); + $cloud = $this->private_clouds_draft_repository->getBy($query); } break; @@ -1159,6 +1285,18 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return ConsultantViewModel::getOfficesLocationsJson($consultant); } + public function getCurrentOfficesLocationsDraftJson() + { + $instance_id = intval($this->request->param('ID')); + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + + $consultant = $this->consultant_draft_repository->getBy($query); + + if (!$consultant) throw new NotFoundEntityException('', ''); + return ConsultantViewModel::getOfficesLocationsJson($consultant); + } + public function getCurrentOfficesLocationsStaticMapForPDF() { $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=1&size=300x200&maptype=roadmap"; @@ -1178,6 +1316,26 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return $static_map_url; } + + public function getCurrentOfficesLocationsStaticMapDraftForPDF() + { + $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=1&size=300x200&maptype=roadmap"; + $instance_id = intval($this->request->param('ID')); + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + + $consultant = $this->consultant_draft_repository->getBy($query); + + if (!$consultant) throw new NotFoundEntityException('', ''); + $locations = json_decode(ConsultantViewModel::getOfficesLocationsJson($consultant)); + + foreach ($locations as $loc) { + $static_map_url .= "&markers=".$loc->lat.",".$loc->lng; + } + + return $static_map_url; + } + public function pdf(){ $html_inner = ''; $marketplace_type = $this->request->param('MARKETPLACETYPE'); @@ -1189,7 +1347,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller switch (strtolower($marketplace_type)) { case 'distribution': { - $distribution = $this->distribution_draft_repository->getBy($query); + $distribution = $this->distribution_repository->getBy($query); if (!$distribution) throw new NotFoundEntityException('', ''); $render = new DistributionSapphireRender($distribution); $distribution ->IsPreview = true; @@ -1264,4 +1422,90 @@ class MarketPlaceAdminPage_Controller extends Page_Controller } } + public function draft_pdf(){ + $html_inner = ''; + $marketplace_type = $this->request->param('MARKETPLACETYPE'); + $instance_id = intval($this->request->param('ID')); + $base = Director::baseFolder(); + + $query = new QueryObject(); + $query->addAddCondition(QueryCriteria::equal('ID', $instance_id)); + + switch (strtolower($marketplace_type)) { + case 'distribution': { + $distribution = $this->distribution_draft_repository->getBy($query); + if (!$distribution) throw new NotFoundEntityException('', ''); + $render = new DistributionSapphireRender($distribution); + $distribution ->IsPreview = true; + $html_inner = $render->pdf(); + $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css"); + } + break; + case 'appliance': { + $appliance = $this->appliance_draft_repository->getBy($query); + $appliance->IsPreview = true; + $render = new ApplianceSapphireRender($appliance); + $html_inner = $render->pdf(); + $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css"); + } + break; + case 'public_cloud': { + $public_cloud = $this->public_clouds_draft_repository->getBy($query); + $public_cloud->IsPreview = true; + if (!$public_cloud) throw new NotFoundEntityException('', ''); + $render = new PublicCloudSapphireRender($public_cloud); + $html_inner = $render->pdf(); + $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css"); + } + break; + case 'private_cloud': { + $private_cloud = $this->private_clouds_draft_repository->getBy($query); + $private_cloud->IsPreview = true; + $render = new PrivateCloudSapphireRender($private_cloud); + $html_inner = $render->pdf(); + $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css"); + + } + break; + case 'consultant': { + $consultant = $this->consultant_draft_repository->getBy($query); + if (!$consultant) throw new NotFoundEntityException('', ''); + $consultant->IsPreview = true; + $render = new ConsultantSapphireRender($consultant); + $html_inner = $render->pdf(); + $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css"); + } + break; + default: + $this->httpError(404); + break; + } + + //create pdf + $file = FileUtils::convertToFileName('preview') . '.pdf'; + + $html_outer = sprintf("
Click any location to see availability zones and API endpoints
<% end_if %> @@ -161,12 +165,22 @@$Type | -<% if Enabled==1 %>Yes<% else %>No<% end_if %> | -
$Type | +<% if Enabled==1 %>Yes<% else %>No<% end_if %> | +
$Type | +<% if Enabled==1 %>Yes<% else %>No<% end_if %> | +
Click any map pin to see office address diff --git a/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss b/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss index bc4f41f..00132fc 100644 --- a/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss +++ b/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss @@ -77,6 +77,7 @@