Exemple #1
0
    def _create_schema_or_context(self, text, repository, entity, data, force_domain_creation, update_if_already_exists, publish):
        try:
            schema_or_context = repository.read(data.organization, data.domain, data.name, data.version)
        except HTTPError as e:
            raise NexusException("Request for {} has failed: {}".format(text, e.message))

        if schema_or_context is None:
            # The schema or context does not exist yet - we create it
            if force_domain_creation:
                organization = self._client.organizations.read(data.organization)
                if organization is None:
                    self._client.organizations.create(Organization.create_new(data.organization, "Created by {} {}".format(text, data.name)))
                domain = self._client.domains.read(data.organization, data.domain)
                if domain is None:
                    self._client.domains.create(Domain.create_new(data.organization, data.domain, "Created by {} {}".format(text, data.name)))
            schema_or_context = repository.create(entity)
        elif update_if_already_exists:
            if schema_or_context.is_published():
                raise NexusException("Can not update the already published {} {}".format(text, data.name))
            schema_or_context = self._client.schemas.update(data.organization, data.domain, data.name, data.version,
                                                            data.content, schema_or_context.get_revision())
        data.revision = schema_or_context.get_revision()
        if publish and data.revision and not schema_or_context.is_published():
            repository.publish(schema_or_context, True, data.revision)
        return data
Exemple #2
0
 def test_create_turtle_instance(self):
     organization = self.client.organizations.read("test")
     if organization is None:
         self.client.organizations.create(
             Organization.create_new("test", "An organization for tests"))
     domain = self.client.domains.read("test", "core")
     if domain is None:
         self.client.domains.create(
             Domain.create_new("test", "core", "A domain for tests"))
     schema = self.client.schemas.read("test", "core", "turtle", "v0.0.4")
     if schema is None:
         schema = self.client.schemas.create(
             Schema.create_new("test",
                               "core",
                               "turtle",
                               "v0.0.4",
                               self.test_turtle_schema,
                               is_turtle=True))
     if not schema.is_published():
         self.client.schemas.publish(schema, True)
     instance = self.client.instances.create(
         Instance.create_new("test",
                             "core",
                             "turtle",
                             "v0.0.4",
                             self.test_turtle_instance,
                             is_turtle=True))
     instance = self.client.instances.read(instance.get_organization(),
                                           instance.get_domain(),
                                           instance.get_schema(),
                                           instance.get_version(),
                                           instance.get_id())
     print instance
Exemple #3
0
 def create_organization(self) -> Optional[Organization]:
     if self.is_organization_pushed():
         self._print_already_pushed(self.organization)
         return None
     else:
         local = Organization.create_new(self.organization,
                                         self.organization_desc)
         distant = self.client.organizations.create(local)
         self._print_pushed(self.organization)
         return distant
Exemple #4
0
 def create_organization(self) -> Organization:
     organization = self.client.organizations.read(self.organization)
     if organization is not None:
         self._print_already_created(self.organization)
         return organization
     else:
         local = Organization.create_new(self.organization, self.organization_desc)
         distant = self.client.organizations.create(local)
         self._print_created(self.organization)
         return distant
Exemple #5
0
 def create_organization(self) -> Organization:
     organization = self.client.organizations.read(self.organization)
     if organization is not None:
         self._print_already_created(self.organization)
         return organization
     else:
         local = Organization.create_new(self.organization,
                                         self.organization_desc)
         distant = self.client.organizations.create(local)
         self._print_created(self.organization)
         return distant
Exemple #6
0
 def resolve(self, search_result):
     identifier = Entity.extract_id_from_url(search_result.self_link,
                                             self.path)
     data = self._read(identifier)
     return Organization(identifier, data,
                         self.path) if data is not None else None
Exemple #7
0
 def read(self, name, revision=None):
     data = self._read(name, revision)
     return Organization(name, data,
                         self.path) if data is not None else None
Exemple #8
0
from pyxus.utils.http_client import HttpClient

nar_client = HttpClient(nar_host)

#
# 2. Create an organisation in KG and list it
#
# Local organization object
#  name, description
#  name should be at most 5 characters
#  host_url/v0/organizations/
#
from pyxus.resources.entity import Organization
from pyxus.resources.repository import OrganizationRepository

naro = Organization.create_new(organisation_name,
                               "HBP Neural Activity Resource")
# create organization on KG
org_repo = OrganizationRepository(nar_client)
org_repo.create(naro)
# List all organisation : new organization should be listed there
kg_organizations = org_repo.list()
[print(x) for x in kg_organizations.results]

#
# 3. Create a new domain and list it. (test_schema)
#
from pyxus.resources.repository import DomainRepository
from pyxus.resources.entity import Domain

naro_tests = Domain.create_new(organisation_name, domain_name, "Test schemas")
# create Domain on naro