Manage an existing collection node.
429511
def mode_collection():
    
    print globals()['mode_collection'].__doc__
    collection_node_id = existing_node_input()
    value = render_value_for_node(collection_node_id)
    if not value:
        return None
    print "Collection length: {0}".format(len(value))
    print safe_dump(value, default_flow_style=False)

    item_attr_list = []
    if len(value):
        for key in value.items()[0][1].keys():
            m = re.match(r'(.*) \((\d+)\)', key)
            item_attr_list.append(m.group(1))

    selection = True
    while selection:
        selection = select([
            'View collection',
            'Add item',
            'Add attribute',
            'Remove item',
            'Remove attribute',
            'Purge collection'
            ])
        if selection == 'View collection':
            print safe_dump(value, default_flow_style=False)
        elif selection == 'Purge collection':
            confirm = raw_input("Delete all {0} items and their {1} attributes from the collection? y/n\n".format(len(value.keys()), len(item_attr_list)))
            if confirm == 'y':
                delete_node(node_id=collection_node_id)
                purge_collection(value.keys())
        elif selection == 'Remove item':
            item_node_id = existing_node_input()
            if item_node_id < 0:
                return
            value = render_value_for_node(item_node_id)
            print safe_dump(value, default_flow_style=False)
            confirm = raw_input("Delete this node and it's attributes? y/n\n").format(len(value.keys()), len(item_attr_list))
            if confirm == 'y':
                delete_node(node_id=item_node_id)
                purge_collection(value.keys())

        elif selection == 'Add item':
            result = select_node(node_id=collection_node_id)
            collection_name = result[0].get('name')

            add_item_with_attributes_to_collection(
                    collection_name=collection_name,
                    collection_node_id=collection_node_id,
                    item_attr_list=item_attr_list)
        elif selection == 'Remove attribute':
            print "Select the attribute that will be removed:"
            attribute_selection = select(item_attr_list)
            if attribute_selection:
                confirm = raw_input("Delete attribute '{0}' from all {1} items in the collection? y/n\n".format(attribute_selection, len(value.keys())))
                if confirm == 'y':
                    for item_key, item in value.items():
                        for key in item.keys():
                            m = re.match(r'(.*) \((\d+)\)', key)
                            if m.group(1) == attribute_selection:
                                delete_node(node_id=m.group(2))
                                break
        elif selection == 'Add attribute':
            item_attr = raw_input("Add a collection item attribute name: ")
            if item_attr:
                item_index = 0
                for item_key, item in value.items():
                    item_index += 1
                    m = re.match(r'(.*) \((\d+)\)', item_key)
                    item_value = render_value_for_node(m.group(2))
                    print "item {0} of {1} items".format(item_index, len(value))
                    print safe_dump(item_value, default_flow_style=False)

                    new_attr_value = raw_input("Enter item attribute value for '{0}': ".format(item_attr))
                    # set value to none if it's an empty string
                    new_attr_value = new_attr_value if len(new_attr_value) else None
                    item_attr_node_id = insert_node(name=item_attr, value=new_attr_value)

                    insert_node_node(node_id=m.group(2), target_node_id=item_attr_node_id)
        # Update the value after each operation
        value = render_value_for_node(collection_node_id)
570358
def put(self, id):
        

        collection_name = self.request.headers.get("collection")

        if not collection_name:
            self.raise_error(400, "Missing a collection name header")

        self.client = BaseAsyncMotorDocument("%s_revisions" % collection_name)

        super(self.__class__, self).put(id)
147220
def move_to_collection(self, request, *args, **kwargs):
        """"""
        ids = self.get_ids(request.data)
        src_collection_id = self.get_id(request.data, 'source_collection')
        dst_collection_id = self.get_id(request.data, 'destination_collection')

        src_collection = self._get_collection_for_user(src_collection_id, request.user)
        dst_collection = self._get_collection_for_user(dst_collection_id, request.user)

        entity_qs = self._get_entities(request.user, ids)
        entity_qs.move_to_collection(src_collection, dst_collection)

        return Response()
850061
protected function submitAddCollection()
    {
        $this->setSubmitted(null, $this->getParam());
        $this->validateComponent('collection');
        $this->addCollection();
    }
148649
public function addCollection(Collection $collection)
    {
        $metadata = $collection->getDocumentMetadata();
        $this->collectionMapping[$metadata->getName()] = $collection;
    }
1044004
def mode_new_collection():
    

    print globals()['mode_new_collection'].__doc__
    collection_name = raw_input("Collection name: ")
    item_attr_list = []
    collection_node_id = None
    if collection_name:
        collection_node_id = insert_node(name=collection_name, value=None)
        insert_query(name='select_link_node_from_node.sql', node_id=collection_node_id)
        item_attr = True
        while item_attr:
            item_attr = raw_input("Add a collection item attribute name: ")
            if item_attr:
                item_attr_list.append(item_attr)

    # if no collection name then exit
    selection = collection_name

    while selection:
        selection = select([
            'Add item',
            ])
        if selection == 'Add item':
            # create item
            add_item_with_attributes_to_collection(
                    collection_name=collection_name,
                    collection_node_id=collection_node_id,
                    item_attr_list=item_attr_list)

    if collection_node_id:
        print "Added collection name '{0}' with node id: {1}".format(collection_name, collection_node_id)
234115
def persist(self, context):
		""""""
		
		D = self._Document
		document = context.session[self.name]
		
		D.get_collection().replace_one(D.id == document.id, document, True)
1257522
function newCollection(_params, _scope) {
      var col = new Collection();
      col.$scope = _scope || Model;
      col.$params = _params;
      col.$initialize();
      return col;
    }
944763
function(node) { 
        var p = node.parent;

        // Update the parent's collection of children
        var a = [];

        for (var i=0, len=p.children.length;i<len;++i) {
            if (p.children[i] != node) {
                a[a.length] = p.children[i];
            }
        }

        p.children = a;

        // reset the childrenRendered flag for the parent
        p.childrenRendered = false;

         // Update the sibling relationship
        if (node.previousSibling) {
            node.previousSibling.nextSibling = node.nextSibling;
        }

        if (node.nextSibling) {
            node.nextSibling.previousSibling = node.previousSibling;
        }

		if (this.currentFocus == node) {
			this.currentFocus = null;
		}
		if (this._currentlyHighlighted == node) {
			this._currentlyHighlighted = null;
		}

        node.parent = null;
        node.previousSibling = null;
        node.nextSibling = null;
        node.tree = null;

        // Update the tree's node collection 
        delete this._nodes[node.index];
    }
814261
public void add(K key, V value) {
    if (treatCollectionsAsImmutable) {
      Collection<V> newC = cf.newCollection();
      Collection<V> c = map.get(key);
      if (c != null) {
        newC.addAll(c);
      }
      newC.add(value);
      map.put(key, newC); // replacing the old collection
    } else {
      Collection<V> c = map.get(key);
      if (c == null) {
        c = cf.newCollection();
        map.put(key, c);
      }
      c.add(value); // modifying the old collection
    }
  }
872066
def collections(self, values):
        """"""
        # if cache server is configured, save collection list
        if self.cache:
            self.cache.set(
                self.app.config['COLLECTIONS_CACHE_KEY'], values)
562682
protected function submitEditCollectionItem()
    {
        if ($this->isPosted('delete')) {
            $this->deleteCollectionItem();
        } else if ($this->isPosted('save') && $this->validateEditCollectionItem()) {
            if (isset($this->data_collection_item['collection_item_id'])) {
                $this->updateCollectionItem();
            } else {
                $this->addCollectionItem();
            }
        }
    }
521879
public void setCollection(String collection) {
        addField(ConfigureNodeFields.collection, FormField.Type.text_single);
        setAnswer(ConfigureNodeFields.collection.getFieldName(), collection);
    }
548922
private void addNewRepos(List<ArtifactoryRepo> repos, List<ArtifactoryRepo> existingRepos, ArtifactoryCollector collector) {
        long start = System.currentTimeMillis();
        int count = 0;

        List<ArtifactoryRepo> newRepos = new ArrayList<>();
        for (ArtifactoryRepo repo : repos) {
            ArtifactoryRepo existing = null;
            if (!CollectionUtils.isEmpty(existingRepos) && (existingRepos.contains(repo))) {
                existing = existingRepos.get(existingRepos.indexOf(repo));
            }

            if (existing == null) {
                repo.setCollectorId(collector.getId());
                repo.setEnabled(false); // Do not enable for collection. Will be enabled later
                repo.setDescription(repo.getRepoName());
                newRepos.add(repo);
                count++;
            }
        }
        //save all in one shot
        if (!CollectionUtils.isEmpty(newRepos)) {
            artifactoryRepoRepository.save(newRepos);
        }
        log("New repos", start, count);
    }
300548
public function addCollection(self $collection)
    {
        // we need to remove all routes with the same names first because just replacing them
        // would not place the new route at the end of the merged array
        foreach ($collection->all() as $name => $route) {
            unset($this->routes[$name]);
            $this->routes[$name] = $route;
        }

        foreach ($collection->getResources() as $resource) {
            $this->addResource($resource);
        }
    }
1264381
def attach(names, parent, dry_run, verbose):
    """"""
    parent = Collection.query.filter_by(name=parent).one()
    collections = Collection.query.filter(Collection.name.in_(names)).all()
    for collection in collections:
        collection.move_inside(parent.id)
        if verbose:
            click.secho(
                'Collection "{0}" is being attached to "{1}".'.format(
                    collection.name, parent
                ), fg='green')
378564
def add_new_collection(self,
                           owner_id,
                           json_repr,
                           auth_info,
                           collection_id=None,
                           commit_msg=''):
        """"""
        collection = self._coerce_json_to_collection(json_repr)
        if collection is None:
            msg = "File failed to parse as JSON:\n{j}".format(j=json_repr)
            raise ValueError(msg)
        if not self._is_valid_collection_json(collection):
            msg = "JSON is not a valid collection:\n{j}".format(j=json_repr)
            raise ValueError(msg)
        if collection_id:
            # try to use this id
            found_owner_id, slug = collection_id.split('/')
            assert found_owner_id == owner_id
        else:
            # extract a working title and "slugify" it
            slug = self._slugify_internal_collection_name(json_repr)
            collection_id = '{i}/{s}'.format(i=owner_id, s=slug)
        # Check the proposed id for uniqueness in any case. Increment until
        # we have a new id, then "reserve" it using a placeholder value.
        with self._index_lock:
            while collection_id in self._doc2shard_map:
                collection_id = increment_slug(collection_id)
            self._doc2shard_map[collection_id] = None
        # pass the id and collection JSON to a proper git action
        new_collection_id = None
        r = None
        try:
            # assign the new id to a shard (important prep for commit_and_try_merge2master)
            gd_id_pair = self.create_git_action_for_new_collection(new_collection_id=collection_id)
            new_collection_id = gd_id_pair[1]
            try:
                # let's remove the 'url' field; it will be restored when the doc is fetched (via API)
                del collection['url']
                # keep it simple (collection is already validated! no annotations needed!)
                r = self.commit_and_try_merge2master(file_content=collection,
                                                     doc_id=new_collection_id,
                                                     auth_info=auth_info,
                                                     parent_sha=None,
                                                     commit_msg=commit_msg,
                                                     merged_sha=None)
            except:
                self._growing_shard.delete_doc_from_index(new_collection_id)
                raise
        except:
            with self._index_lock:
                if new_collection_id in self._doc2shard_map:
                    del self._doc2shard_map[new_collection_id]
            raise
        with self._index_lock:
            self._doc2shard_map[new_collection_id] = self._growing_shard
        return new_collection_id, r