示例#1
0
    def create(collection_path, git_name, git_mail):
        """create new entity given an entity ID
        TODO remove write and commit, just create object
        """
        # write collection.json template to collection location and commit
        fileio.write_text(Collection(collection_path).dump_json(template=True),
                   settings.TEMPLATE_CJSON)
        templates = [settings.TEMPLATE_CJSON, settings.TEMPLATE_EAD]
        agent = settings.AGENT

        cidentifier = Identifier(collection_path)
        exit,status = commands.create(
            git_name, git_mail, cidentifier, templates, agent
        )
        
        collection = Collection.from_identifier(cidentifier)
        
        # [delete cache], update search index
        #collection.cache_delete()
        if settings.DOCSTORE_ENABLED:
            try:
                docstore.Docstore().post(self)
            except ConnectionError:
                logger.error('Could not post to Elasticsearch.')
        
        return collection
示例#2
0
 def create(identifier, git_name, git_mail, agent='cmdln'):
     """Creates new Collection, writes files, performs initial commit
     
     @param identifier: Identifier
     @param git_name: str
     @param git_mail: str
     @param agent: str
     @returns: exit,status int,str
     """
     exit, status = commands.create(
         user_name=git_name,
         user_mail=git_mail,
         identifier=identifier,
         agent=agent,
     )
     return exit, status
示例#3
0
 def new(identifier, git_name, git_mail, agent='cmdln'):
     """Creates new Collection, writes to filesystem, performs initial commit
     
     @param identifier: Identifier
     @param git_name: str
     @param git_mail: str
     @param agent: str
     @returns: exit,status int,str
     """
     collection = Collection.create(identifier.path_abs(), identifier)
     fileio.write_text(collection.dump_json(template=True),
                       config.TEMPLATE_CJSON)
     exit, status = commands.create(
         git_name,
         git_mail,
         identifier, [config.TEMPLATE_CJSON, config.TEMPLATE_EAD],
         agent=agent)
     return exit, status
示例#4
0
def new( request, repo, org ):
    """Gets new CID from workbench, creates new collection record.
    
    If it messes up, goes back to collection list.
    """
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not (git_name and git_mail):
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    # get new collection ID
    try:
        collection_ids = api.collections_next(request, repo, org, 1)
    except Exception as e:
        logger.error('Could not get new collecion ID!')
        logger.error(str(e.args))
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_ERR_NO_IDS'])
        messages.error(request, e)
        return HttpResponseRedirect(reverse('webui-collections'))
    cid = int(collection_ids[-1].split('-')[2])
    # create the new collection repo
    collection_path = Collection.collection_path(request,repo,org,cid)
    # collection.json template
    Collection(collection_path).dump_json(path=settings.TEMPLATE_CJSON, template=True)
    exit,status = commands.create(git_name, git_mail,
                                  collection_path,
                                  [settings.TEMPLATE_CJSON, settings.TEMPLATE_EAD],
                                  agent=settings.AGENT)
    if exit:
        logger.error(exit)
        logger.error(status)
        messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
    else:
        # update search index
        json_path = os.path.join(collection_path, 'collection.json')
        with open(json_path, 'r') as f:
            document = json.loads(f.read())
        docstore.post(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX, document)
        gitstatus_update.apply_async((collection_path,), countdown=2)
        # positive feedback
        return HttpResponseRedirect( reverse('webui-collection-edit', args=[repo,org,cid]) )
    # something happened...
    logger.error('Could not create new collecion!')
    messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_ERR_CREATE'])
    return HttpResponseRedirect(reverse('webui-collections'))
示例#5
0
 def create(collection_path, git_name, git_mail):
     """create new entity given an entity ID
     """
     # write collection.json template to collection location and commit
     Collection(collection_path).dump_json(path=settings.TEMPLATE_CJSON, template=True)
     templates = [settings.TEMPLATE_CJSON, settings.TEMPLATE_EAD]
     agent = settings.AGENT
     
     exit,status = commands.create(
         git_name, git_mail, collection_path, templates, agent)
     
     collection = Collection.from_json(collection_path)
     
     # [delete cache], update search index
     #collection.cache_delete()
     with open(collection.json_path, 'r') as f:
         document = json.loads(f.read())
     docstore.post(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX, document)
     
     return collection
示例#6
0
def new( request, repo, org ):
    """Gets new CID from workbench, creates new collection record.
    
    If it messes up, goes back to collection list.
    """
    oidentifier = Identifier(request)
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not (git_name and git_mail):
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    
    ic = idservice.IDServiceClient()
    # resume session
    auth_status,auth_reason = ic.resume(request.session['idservice_token'])
    if auth_status != 200:
        request.session['idservice_username'] = None
        request.session['idservice_token'] = None
        messages.warning(
            request,
            'Session resume failed: %s %s (%s)' % (
                auth_status,auth_reason,settings.IDSERVICE_API_BASE
            )
        )
        return HttpResponseRedirect(reverse('webui-collections'))
    # get new collection ID
    http_status,http_reason,collection_id = ic.next_object_id(
        oidentifier,
        'collection'
    )
    if http_status not in [200,201]:
        err = '%s %s' % (http_status, http_reason)
        msg = WEBUI_MESSAGES['VIEWS_COLL_ERR_NO_IDS'] % (settings.IDSERVICE_API_BASE, err)
        logger.error(msg)
        messages.error(request, msg)
        return HttpResponseRedirect(reverse('webui-collections'))
    
    identifier = Identifier(id=collection_id, base_path=settings.MEDIA_BASE)
    # create the new collection repo
    collection_path = identifier.path_abs()
    # collection.json template
    fileio.write_text(
        Collection(collection_path).dump_json(template=True),
        settings.TEMPLATE_CJSON
    )
    exit,status = commands.create(
        git_name, git_mail,
        identifier,
        [settings.TEMPLATE_CJSON, settings.TEMPLATE_EAD],
        agent=settings.AGENT
    )
    if exit:
        logger.error(exit)
        logger.error(status)
        messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
    else:
        # update search index
        collection = Collection.from_identifier(identifier)
        try:
            collection.post_json(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX)
        except ConnectionError:
            logger.error('Could not post to Elasticsearch.')
        gitstatus_update.apply_async((collection_path,), countdown=2)
        # positive feedback
        return HttpResponseRedirect( reverse('webui-collection-edit', args=collection.idparts) )
    # something happened...
    logger.error('Could not create new collecion!')
    messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_ERR_CREATE'])
    return HttpResponseRedirect(reverse('webui-collections'))