How to use the girder.models.item.Item function in girder

To help you get started, we’ve selected a few girder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github girder / large_image / girder_annotation / test_annotation / test_annotations.py View on Github external
def testGetElements(self, admin):
        publicFolder = utilities.namedFolder(admin, 'Public')
        item = Item().createItem('sample', admin, publicFolder)
        largeSample = makeLargeSampleAnnotation()
        # Use a copy of largeSample so we don't just have a referecne to it
        annot = Annotation().createAnnotation(item, admin, largeSample.copy())
        # Clear existing element data, the get elements
        annot.pop('elements', None)
        annot.pop('_elementQuery', None)
        Annotationelement().getElements(annot)
        assert '_elementQuery' in annot
        assert len(annot['annotation']['elements']) == len(largeSample['elements'])  # 7707
        assert 'centroids' not in annot['_elementQuery']
        annot.pop('elements', None)
        annot.pop('_elementQuery', None)
        Annotationelement().getElements(annot, {'limit': 100})
        assert '_elementQuery' in annot
        assert annot['_elementQuery']['count'] == len(largeSample['elements'])
        assert annot['_elementQuery']['returned'] == 100
github girder / large_image / girder_annotation / test_annotation / test_annotations_rest.py View on Github external
def testAnnotationsAfterCopyItem(self, server, admin):
        publicFolder = utilities.namedFolder(admin, 'Public')
        item = Item().createItem('sample', admin, publicFolder)
        Annotation().createAnnotation(item, admin, sampleAnnotation)
        resp = server.request(
            '/annotation', user=admin, params={'itemId': item['_id']})
        assert utilities.respStatus(resp) == 200
        assert len(resp.json) == 1
        resp = server.request(
            '/item/%s/copy' % item['_id'], method='POST', user=admin)
        assert utilities.respStatus(resp) == 200
        resp = server.request(
            '/annotation', user=admin, params={'itemId': resp.json['_id']})
        assert utilities.respStatus(resp) == 200
        assert len(resp.json) == 1
        resp = server.request(
            '/item/%s/copy' % item['_id'], method='POST', user=admin,
            params={'copyAnnotations': 'true'})
        assert utilities.respStatus(resp) == 200
github girder / large_image / girder_annotation / test_annotation / test_annotations_rest.py View on Github external
def makeAnnot(self, admin):
        publicFolder = utilities.namedFolder(admin, 'Public')

        self.item = Item().createItem('sample', admin, publicFolder)
        annotationModel = Annotation()

        self.noGroups = annotationModel.createAnnotation(
            self.item, admin,
            {
                'name': 'nogroups',
                'elements': [{
                    'type': 'rectangle',
                    'center': [20.0, 25.0, 0],
                    'width': 14.0,
                    'height': 15.0,
                }, {
                    'type': 'rectangle',
                    'center': [40.0, 15.0, 0],
                    'width': 5.0,
                    'height': 5.0
github girder / girder_worker / tests / integration / integration_test_endpoints / integration_test_endpoints / docker.py View on Github external
                    model=Item, destName='item',
                    level=AccessType.READ, paramType='query')
        .param('delimiter', 'Delimiter to use when writing out chunks.'))
    def input_stream(self, item, delimiter):
        chunks = six.BytesIO()
        for chunk in iterBody(1):
            chunks.write(chunk)
            chunks.write(delimiter.encode('utf-8'))

        chunks.seek(0)
        contents = chunks.read()
        chunks.seek(0)
        Upload().uploadFromFile(
            chunks, len(contents), 'chunks', parentType='item', parent=item,
            user=getCurrentUser())
github girder / girder / plugins / item_tasks / girder_item_tasks / json_tasks.py View on Github external
                model=Item, level=AccessType.WRITE)
    .param('image', 'The docker image name. If not passed, uses the existing'
           'itemTaskSpec.docker_image metadata value.', required=False, strip=True)
    .param('taskName', 'The task name.', required=True, strip=True)
    .param('setName', 'Whether item name should be changed to the title of the CLI.',
           dataType='boolean', required=False, default=True)
    .param('setDescription', 'Whether the item description should be changed to the '
           'description of the CLI.', dataType='boolean', required=False, default=True)
    .param('pullImage', 'Whether the image should be pulled from Docker Hub. '
           'Set to false to use local images only.',
           dataType='boolean', required=False, default=True)
)
def runJsonTasksDescriptionForItem(self, item, image, taskName, setName, setDescription,
                                   pullImage, params):
    if 'meta' not in item:
        item['meta'] = {}
github girder / girder / plugins / metadata_extractor / server / metadata_extractor.py View on Github external
def _setMetadata(self):
        """
        Attach metadata to item on server.

        """
        super(ServerMetadataExtractor, self)._setMetadata()
        item = Item().load(self.itemId, force=True)
        Item().setMetadata(item, self.metadata)
github girder / girder / girder / cli / mount.py View on Github external
:returns: a list of the names of resources within the specified
        document.
        """
        entries = []
        if model in ('collection', 'user', 'folder'):
            folderList = Folder().find({
                'parentId': doc['_id'],
                'parentCollection': model.lower()
            })
            for folder in folderList:
                entries.append(self._name(folder, 'folder'))
        if model == 'folder':
            for item in Folder().childItems(doc):
                entries.append(self._name(item, 'item'))
        elif model == 'item':
            for file in Item().childFiles(doc):
                entries.append(self._name(file, 'file'))
        return entries
github girder / girder / plugins / audit_logs / scripts / report.py View on Github external
def index_folder(folderId):
    if Folder().load(folderId, force=True) is None:
        raise ValueError('folderId={} was not a valid folder'.format(folderId))
    items = Item().find({'folderId': ObjectId(folderId)})
    subfolders = Folder().find({'parentId': ObjectId(folderId)})

    files = []
    for item in items:
        for file in Item().childFiles(item, fields={'_id': True}):
            fileId = file['_id']
            files.append(fileId)

    for folder in subfolders:
        files += index_folder(folder['_id'])

    return files
github girder / girder / plugins / item_tasks / girder_item_tasks / json_tasks.py View on Github external
Token().requireScope(self.getCurrentToken(), 'item_task.set_task_spec.%s' % item['_id'])

    if not isinstance(json, list):
        json = [json]

    for itemIndex, itemTaskSpec in enumerate(json):
        specName = itemTaskSpec.get('name')
        if specName == taskName:
            if setName:
                item['name'] = taskName
            if setDescription:
                item['description'] = itemTaskSpec.get('description', '')

            itemTaskSpec['docker_image'] = image
            itemTaskSpec['pull_image'] = pullImage
            Item().setMetadata(item, {
                'itemTaskName': taskName,
                'itemTaskSpec': itemTaskSpec,
                'isItemTask': True
            })
            break
    else:
        raise RestException('Task with name "%s" not found in JSON specification' % taskName)
github girder / large_image / server / base.py View on Github external
def _postUpload(event):
    """
    Called when a file is uploaded. We check the parent item to see if it is
    expecting a large image upload, and if so we register this file as the
    result image.
    """
    fileObj = event.info['file']
    # There may not be an itemId (on thumbnails, for instance)
    if not fileObj.get('itemId'):
        return

    item = Item().load(fileObj['itemId'], force=True, exc=True)

    if item.get('largeImage', {}).get('expected') and (
            fileObj['name'].endswith('.tiff') or
            fileObj.get('mimeType') == 'image/tiff'):
        if fileObj.get('mimeType') != 'image/tiff':
            fileObj['mimeType'] = 'image/tiff'
            File().save(fileObj)
        del item['largeImage']['expected']
        item['largeImage']['fileId'] = fileObj['_id']
        item['largeImage']['sourceName'] = 'tiff'
        Item().save(item)