Builds the resource object (type, id, attributes) and extracts relationships.
505927
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
                                force_type_resolution=False):
        
        # Determine type from the instance if the underlying model is polymorphic
        if force_type_resolution:
            resource_name = utils.get_resource_type_from_instance(resource_instance)
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
            ('attributes', cls.extract_attributes(fields, resource)),
        ]
        relationships = cls.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data)
857387
def gen_relationships(obj) -> Generator[Tuple[str, RelationshipProperty, Type],
                                        None, None]:
    
    insp = inspect(obj)  # type: InstanceState
    # insp.mapper.relationships is of type
    # sqlalchemy.utils._collections.ImmutableProperties, which is basically
    # a sort of AttrDict.
    for attrname, rel_prop in insp.mapper.relationships.items():  # type: Tuple[str, RelationshipProperty]  # noqa
        # noinspection PyUnresolvedReferences
        related_class = rel_prop.mapper.class_
        # log.critical("gen_relationships: attrname={!r}, "
        #              "rel_prop={!r}, related_class={!r}, rel_prop.info={!r}",
        #              attrname, rel_prop, related_class, rel_prop.info)
        yield attrname, rel_prop, related_class
804826
public ResourceRegistry build(ResourceLookup resourceLookup, ModuleRegistry moduleRegistry, ServiceUrlProvider serviceUrl) {
		Set<Class<?>> jsonApiResources = resourceLookup.getResourceClasses();

		Set<ResourceInformation> resourceInformationSet = new HashSet<>(jsonApiResources.size());
		

		for (Class<?> clazz : jsonApiResources) {
			resourceInformationSet.add(resourceInformationBuilder.build(clazz));
			LOGGER.trace("{} registered as a resource", clazz);
		}

		Set<RegistryEntry> registryEntries = new HashSet<>(resourceInformationSet.size());
		for (ResourceInformation resourceInformation : resourceInformationSet) {
			Class<?> resourceClass = resourceInformation.getResourceClass();

			ResourceEntry resourceEntry = repositoryEntryBuilder.buildResourceRepository(resourceLookup, resourceClass);
			LOGGER.trace("{} has a resource repository {}", resourceInformation.getResourceClass(), resourceEntry);
			List<ResponseRelationshipEntry> relationshipEntries = repositoryEntryBuilder.buildRelationshipRepositories(resourceLookup, resourceClass);
			LOGGER.trace("{} has relationship repositories {}", resourceInformation.getResourceClass(), relationshipEntries);

			ResourceRepositoryInformation repositoryInformation = new ResourceRepositoryInformationImpl(null, resourceInformation.getResourceType(), resourceInformation);
			registryEntries.add(new RegistryEntry(repositoryInformation, resourceEntry, relationshipEntries));
		}

		ResourceRegistry resourceRegistry = new ResourceRegistryImpl(moduleRegistry, serviceUrl);
		for (RegistryEntry registryEntry : registryEntries) {
			Class<?> resourceClass = registryEntry.getResourceInformation().getResourceClass();
			RegistryEntry registryEntryParent = findParent(resourceClass, registryEntries);
			registryEntry.setParentRegistryEntry(registryEntryParent);
			resourceRegistry.addEntry(resourceClass, registryEntry);
		}

		return resourceRegistry;
	}
793944
protected void importRelations(CmsResource resource, Element parentElement) {

        // Get the nodes for the relations
        @SuppressWarnings("unchecked")
        List<Node> relationElements = parentElement.selectNodes(
            "./" + A_CmsImport.N_RELATIONS + "/" + A_CmsImport.N_RELATION);

        List<CmsRelation> relations = new ArrayList<CmsRelation>();
        // iterate over the nodes
        Iterator<Node> itRelations = relationElements.iterator();
        while (itRelations.hasNext()) {
            Element relationElement = (Element)itRelations.next();
            String structureID = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_ID);
            String targetPath = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_PATH);
            String relationType = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_TYPE);
            CmsUUID targetId = new CmsUUID(structureID);
            CmsRelationType type = CmsRelationType.valueOf(relationType);

            CmsRelation relation = new CmsRelation(
                resource.getStructureId(),
                resource.getRootPath(),
                targetId,
                targetPath,
                type);

            relations.add(relation);
        }

        if (!relations.isEmpty()) {
            m_importedRelations.put(resource.getRootPath(), relations);
        }
    }
277784
static List<UberData> extractLinksAndContent(CollectionModel<?> resources) {

		List<UberData> data = extractLinks(resources);

		data.addAll(resources.getContent().stream().map(UberData::doExtractLinksAndContent)
				.map(uberData -> new UberData().withData(uberData)).collect(Collectors.toList()));

		return data;
	}
1160427
def apply_relationships(self, data, obj):
        
        relationships_to_apply = []
        relationship_fields = get_relationships(self.resource.schema, model_field=True)
        for key, value in data.items():
            if key in relationship_fields:
                related_model = getattr(obj.__class__, key).property.mapper.class_
                schema_field = get_schema_field(self.resource.schema, key)
                related_id_field = self.resource.schema._declared_fields[schema_field].id_field

                if isinstance(value, list):
                    related_objects = []

                    for identifier in value:
                        related_object = self.get_related_object(related_model, related_id_field, {'id': identifier})
                        related_objects.append(related_object)

                    relationships_to_apply.append({'field': key, 'value': related_objects})
                else:
                    related_object = None

                    if value is not None:
                        related_object = self.get_related_object(related_model, related_id_field, {'id': value})

                    relationships_to_apply.append({'field': key, 'value': related_object})

        for relationship in relationships_to_apply:
            setattr(obj, relationship['field'], relationship['value'])
672199
def _dataset_create_resources(self):
        # type: () -> None
        

        if 'resources' in self.data:
            self.old_data['resources'] = self._copy_hdxobjects(self.resources, hdx.data.resource.Resource, 'file_to_upload')
            self.init_resources()
            self.separate_resources()
124358
def parse_resources(html):
    """"""
    xpath = '//*[@data-type="resources"]//xhtml:li/xhtml:a'
    for resource in html.xpath(xpath, namespaces=HTML_DOCUMENT_NAMESPACES):
        yield {
            'id': resource.get('href'),
            'filename': resource.text.strip(),
            }
134504
def build(self):
        

        result = {}

        for lambda_function in self._functions_to_build:

            LOG.info("Building resource '%s'", lambda_function.name)
            result[lambda_function.name] = self._build_function(lambda_function.name,
                                                                lambda_function.codeuri,
                                                                lambda_function.runtime)

        return result
898371
def build(self) -> type:
        
        def _get_property_mappings(encoder: MappingJSONEncoder) -> List[JsonPropertyMapping]:
            return _get_all_property_mappings(encoder, self.mappings, self.superclasses)

        def get_deserializable_cls(decoder: MappingJSONDecoder) -> type:
            return self.target_cls

        return type(
            "%sDynamicMappingJSONDecoder" % self.target_cls.__name__,
            self.superclasses,
            {
                "_get_property_mappings": _get_property_mappings,
                "_get_deserializable_cls": get_deserializable_cls
            }
        )
181429
def from_api_repr(cls, resource):
        
        name = resource.get("name")
        type_ = resource["parameterType"]["type"]
        value = resource["parameterValue"]["value"]
        converted = _QUERY_PARAMS_FROM_JSON[type_](value, None)
        return cls(name, type_, converted)
262885
def get_resources(cls):
        """"""
        my_plurals = resource_helper.build_plural_mappings(
            {}, RESOURCE_ATTRIBUTE_MAP)
        attributes.PLURALS.update(my_plurals)
        attr_map = RESOURCE_ATTRIBUTE_MAP
        ext_resources = resource_helper.build_resource_info(my_plurals,
                                                            attr_map,
                                                            constants.A10_CERTIFICATE)

        return ext_resources
1132137
def get_relationship_form(self, *args, **kwargs):
        """"""
        # Implemented from kitosid template for -
        # osid.resource.ResourceAdminSession.get_resource_form_for_update
        # This method might be a bit sketchy. Time will tell.
        if isinstance(args[-1], list) or 'relationship_record_types' in kwargs:
            return self.get_relationship_form_for_create(*args, **kwargs)
        else:
            return self.get_relationship_form_for_update(*args, **kwargs)
986521
def _get_resources_by_type(self, resource_type):
        
        resources = []
        for res in self.dsDoc['dataResources']:
            if res['resType'] == resource_type:
                resources.append(res)

        return resources
1295020
def get_resource_types(self):
        
        resource_types = set()
        for model in self.models():
            for field in self.model_file_fields(model):
                resource_type = field.storage.RESOURCE_TYPE
                resource_types.add(resource_type)
        return resource_types
471406
public RelationTypeImpl buildRelationType(VertexElement vertex, RelationType type) {
        return getOrBuildConcept(vertex, (v) -> RelationTypeImpl.create(v, type));
    }
39312
def resource_attributes_by_type(ast)
      result = {}
      resources_by_type(ast).each do |type, resources|
        result[type] = resources.map do |resource|
          resource_attributes(resource)
        end
      end
      result
    end