def test_upload(self, name, content_type, data, repository, expected_url, res_name=None, is_resource=False, side_effect=None, err_msg=None): # Build repository adaptor object repository_adaptor = repositoryAdaptor.repository_adaptor_factory(repository, is_resource=is_resource) repository_adaptor.set_credentials('11111') # Execute test self._execute_test( repository_adaptor.upload, (content_type, data, res_name), self._check_upload_response, (expected_url, content_type, data), side_effect, err_msg )
def test_upload(self, name, content_type, data, repository, expected_url, res_name=None, is_resource=False, side_effect=None, err_msg=None): # Build repository adaptor object repository_adaptor = repositoryAdaptor.repository_adaptor_factory( repository, is_resource=is_resource) repository_adaptor.set_credentials('11111') # Execute test self._execute_test(repository_adaptor.upload, (content_type, data, res_name), self._check_upload_response, (expected_url, content_type, data), side_effect, err_msg)
def _upload_usdl(resource, user): # Upload the rdf of the resource to the repository if existing usdl_url = "" if len(Repository.objects.all()) > 0: usdl, resource_uri = _build_usdl(resource) repository = Repository.objects.get(is_default=True) repository_adaptor = repository_adaptor_factory(repository, is_resource=True) resource_id = resource.pk + '__' + resource.provider.name + '__' + resource.name.replace(' ', '_') + '__' + resource.version repository_adaptor.set_uri(resource_uri) repository_adaptor.set_credentials(user.userprofile.access_token) usdl_url = repository_adaptor.upload('application/rdf+xml', usdl, resource_id) else: resource_uri = resource.get_uri() resource.resource_usdl = usdl_url resource.resource_uri = resource_uri resource.save()
def _upload_usdl(resource, user): # Upload the rdf of the resource to the repository if existing usdl_url = "" if len(Repository.objects.all()) > 0: usdl, resource_uri = _build_usdl(resource) repository = Repository.objects.get(is_default=True) repository_adaptor = repository_adaptor_factory(repository, is_resource=True) resource_id = resource.pk + '__' + resource.provider.name + '__' + resource.name.replace( ' ', '_') + '__' + resource.version repository_adaptor.set_uri(resource_uri) repository_adaptor.set_credentials(user.userprofile.access_token) usdl_url = repository_adaptor.upload('application/rdf+xml', usdl, resource_id) else: resource_uri = resource.get_uri() resource.resource_usdl = usdl_url resource.resource_uri = resource_uri resource.save()
def publish_offering(user, offering, data): # Validate data if 'marketplaces' not in data: raise ValueError('Publication error: missing required field, marketplaces') # Validate the state of the offering if not offering.state == 'uploaded': raise PermissionDenied('Publication error: The offering ' + offering.name + ' ' + offering.version + ' cannot be published') # Validate the offering has enough content to be published # Open offerings cannot be published in they do not contain # digital assets (applications or resources) if offering.open and not len(offering.resources) and not len(offering.applications): raise PermissionDenied('Publication error: Open offerings cannot be published if they do not contain at least a digital asset (resource or application)') # Check if it possible to publish the offering in a Marketplace if not len(Repository.objects.all()) > 0 and len(data['marketplaces']) > 0: raise PermissionDenied('Publication error: It is not possible to publish an offering in a Markteplace if no Repositories has been registered') # Upload the USDL description of the offering to the repository if len(Repository.objects.all()) > 0: repository = Repository.objects.get(is_default=True) # Generate the USDL of the offering generator = USDLGenerator() usdl, offering_uri = generator.generate_offering_usdl(offering) repository_adaptor = repository_adaptor_factory(repository) offering_id = offering.owner_organization.name + '__' + offering.name + '__' + offering.version repository_adaptor.set_uri(offering_uri) if settings.OILAUTH: repository_adaptor.set_credentials(user.userprofile.access_token) offering.description_url = repository_adaptor.upload('application/rdf+xml', usdl, name=offering_id) # Publish the offering in the selected marketplaces for market in data['marketplaces']: try: m = Marketplace.objects.get(name=market) except: raise ValueError('Publication error: The marketplace ' + market + ' does not exist') market_adaptor = marketadaptor_factory(m, user) off_market_name = market_adaptor.add_service(offering) offering.marketplaces.append(MarketOffering( marketplace=m, offering_name=off_market_name )) # Create revenue sharing models if needed build_rs_model(offering) offering.state = 'published' offering.publication_date = datetime.now() offering.save() # Update offering indexes index_path = os.path.join(settings.BASEDIR, 'wstore') index_path = os.path.join(index_path, 'search') index_path = os.path.join(index_path, 'indexes') se = SearchEngine(index_path) se.update_index(offering)