<commit_before># -*- coding: utf-8 -*-

import os
import requests
from seadata.apis.commons.cluster import ClusterContainerEndpoint
from b2stage.apis.commons.b2access import B2accessUtilities
from restapi import decorators as decorate
from restapi.protocols.bearer import authentication
from restapi.exceptions import RestApiException
from restapi.flask_ext.flask_celery import CeleryExt
from restapi.utilities.htmlcodes import hcodes
from restapi.utilities.logs import get_logger

log = get_logger(__name__)


class PidCache(ClusterContainerEndpoint, B2accessUtilities):

    # schema_expose = True
    labels = ['helper']
    depends_on = ['SEADATA_PROJECT']
    GET = {
        '/pidcache': {
            'custom': {'publish': False},
            'summary': 'Retrieve values from the PID cache',
            'responses': {'200': {'description': 'Async job started'}},
        }
    }
    POST = {
        '/pidcache/<batch_id>': {
            'custom': {'publish': False},
            'summary': 'Fill the PID cache',
            'responses': {'200': {'description': 'Async job started'}},
        }
    }

    @decorate.catch_error()
    @authentication.required(roles=['admin_root', 'staff_user'], required_roles='any')
    def get(self):

        task = CeleryExt.inspect_pids_cache.apply_async()
        log.info("Async job: %s", task.id)
        return self.return_async_id(task.id)

    @decorate.catch_error()
    @authentication.required(roles=['admin_root', 'staff_user'], required_roles='any')
    def post(self, batch_id):

        # imain = self.get_service_instance(service_name='irods')
        try:
            imain = self.get_main_irods_connection()
            ipath = self.get_irods_production_path(imain)

            collection = os.path.join(ipath, batch_id)
            if not imain.exists(collection):
                raise RestApiException(
                    "Invalid batch id %s" % batch_id, status_code=hcodes.HTTP_BAD_NOTFOUND
                )

            task = CeleryExt.cache_batch_pids.apply_async(args=[collection])
            log.info("Async job: %s", task.id)

            return self.return_async_id(task.id)
        except requests.exceptions.ReadTimeout:
            return self.send_errors(
                "B2SAFE is temporarily unavailable",
                code=hcodes.HTTP_SERVICE_UNAVAILABLE
            )
<commit_msg>Removed deprecated use of publish flag in swagger specs<commit_after># -*- coding: utf-8 -*-

import os
import requests
from seadata.apis.commons.cluster import ClusterContainerEndpoint
from b2stage.apis.commons.b2access import B2accessUtilities
from restapi import decorators as decorate
from restapi.protocols.bearer import authentication
from restapi.exceptions import RestApiException
from restapi.flask_ext.flask_celery import CeleryExt
from restapi.utilities.htmlcodes import hcodes
from restapi.utilities.logs import get_logger

log = get_logger(__name__)


class PidCache(ClusterContainerEndpoint, B2accessUtilities):

    # schema_expose = True
    labels = ['helper']
    depends_on = ['SEADATA_PROJECT']
    GET = {
        '/pidcache': {
            'summary': 'Retrieve values from the PID cache',
            'responses': {'200': {'description': 'Async job started'}},
        }
    }
    POST = {
        '/pidcache/<batch_id>': {
            'summary': 'Fill the PID cache',
            'responses': {'200': {'description': 'Async job started'}},
        }
    }

    @decorate.catch_error()
    @authentication.required(roles=['admin_root', 'staff_user'], required_roles='any')
    def get(self):

        task = CeleryExt.inspect_pids_cache.apply_async()
        log.info("Async job: %s", task.id)
        return self.return_async_id(task.id)

    @decorate.catch_error()
    @authentication.required(roles=['admin_root', 'staff_user'], required_roles='any')
    def post(self, batch_id):

        # imain = self.get_service_instance(service_name='irods')
        try:
            imain = self.get_main_irods_connection()
            ipath = self.get_irods_production_path(imain)

            collection = os.path.join(ipath, batch_id)
            if not imain.exists(collection):
                raise RestApiException(
                    "Invalid batch id %s" % batch_id, status_code=hcodes.HTTP_BAD_NOTFOUND
                )

            task = CeleryExt.cache_batch_pids.apply_async(args=[collection])
            log.info("Async job: %s", task.id)

            return self.return_async_id(task.id)
        except requests.exceptions.ReadTimeout:
            return self.send_errors(
                "B2SAFE is temporarily unavailable",
                code=hcodes.HTTP_SERVICE_UNAVAILABLE
            )

{'fraction_non_alphanumeric': 0.10770540655598126, 'fraction_numerical': 0.005108556832694764, 'mean_word_length': 2.7925746569814365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2482413', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1382, 'n_words': 292}