def __init__(self, tid=None, ip=None):

        logger = logging.getLogger('Avispa')
        self.lggr = AvispaLoggerAdapter(logger, {'tid': tid, 'ip': ip})

        self.RIM = RingsModel(tid=tid, ip=ip)
        self.COM = CollectionsModel(tid=tid, ip=ip)
        self.CB = CollectionBuilder(tid=tid, ip=ip)
Example #2
0
    def __init__(self,tid=None,ip=None):

        logger = logging.getLogger('Avispa')
        self.lggr = AvispaLoggerAdapter(logger, {'tid': tid,'ip': ip})

        self.collectionprotocols = {}
        self.collectionprotocols['collectionprotocol'] = ['CollectioNname','CollectionDescription','CollectionVersion']
        self.collectionprotocols['mandatory'] = ['CollectionName']
        self.collectionprotocols['defaults'] = {'CollectionVersion':'0.1.0'}
        self.COM = CollectionsModel()
Example #3
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)

        self._provider = ReminderApiProvider('http://localhost:8080')
        self._collections_model = CollectionsModel(self._provider)
        self._table_model = None

        self._ui.comboBox.setModel(self._collections_model)
        self._ui.comboBox.currentTextChanged.connect(self._set_collection)

        self._collections_model.update_model()
        self._set_collection(self._ui.comboBox.currentText())
Example #4
0
    def collectionbatch(self, request, *args):

        from RingsController import RingsController
        from RingsModel import RingsModel
        from CollectionsModel import CollectionsModel
        from RingBuilder import RingBuilder

        #Step 0 Prerequirements
        source_handle = request.args.get("source_handle")
        target_handle = request.args.get("target_handle")
        source_collection = request.args.get("source_collection")
        target_collection = request.args.get("target_collection")
        rqurl = request.url

        print(rqurl)

        #Step 1 Get collection with list of its Rings
        #INPUT: source_handle,collection
        #OUTPUT: collectiond
        COM = CollectionsModel()
        collectiond = COM.get_a_x_y(source_handle, source_collection)

        print(collectiond)

        #Step 2 Get ringlist from source_handle
        #INPUT: source_handle
        #OUTPUT: ringlist
        RIM = RingsModel()
        ringlist = RIM.user_get_rings(source_handle)

        print(ringlist)

        #Step 3 Verify that origin source_handle has all the rings needed
        #INPUT: collectiond,ringlist
        #RETURN: collectiond_verified

        existing_rings = []
        collectiond_verified = {}
        for rr in ringlist:
            existing_rings.append(rr['ringname'])

        rings_verified = []
        for ring in collectiond['rings']:
            if ring['ringname'] in existing_rings:
                ring['handle'] = target_handle
                rings_verified.append(ring)

        #Step 4 Check if a collection with that name already exists at the target_handle
        #INPUT: target_handle,collection
        #OUTPUT: <success>
        COM = CollectionsModel()
        collectionlist = COM.get_a_x(target_handle)
        for c in collectionlist:
            if c['collectionname'] == target_collection:
                raise Exception(
                    'Collection Name Already in use, use another one')

        #Step 5  Clone all the rings in target_handle
        #INPUT: baseurl,target_handle, collectiond_verified
        #RETURN: collectiond_built

        RB = RingBuilder()

        o1 = urlparse.urlparse(rqurl)
        rings_built = []
        collectiond_built = {}

        for ring in rings_verified:

            path = '%s/%s' % (source_handle, ring['ringname'])
            ringurl = urlparse.urlunparse(
                (o1.scheme, o1.netloc, path, '', '', ''))
            rqform = {'ringurl': ringurl}

            ring_post_result = RB.post_a(rqurl, rqform, target_handle)

            if ring_post_result:
                ring['handle'] = target_handle
                rings_built.append(ring)

        #Step 6 Build the collection
        #INPUT: target_handle,target_collection,rings_verified
        #RETURN: <success>

        COM = CollectionsModel()
        #collectiond['ringlist'] = collectiond_built['rings']
        collectiond[
            'ringlist'] = rings_verified  #Build collection no matter what
        collectiond['name'] = target_collection
        collection_post_result = COM.post_a_x(target_handle, collectiond)

        #Step 7 Redirect

        redirect = url_for('avispa_rest.home',
                           handle=target_handle,
                           _external=True,
                           _scheme=URL_SCHEME)

        return {'redirect': redirect, 'status': 200}
Example #5
0
class CollectionBuilder:

    def __init__(self,tid=None,ip=None):

        logger = logging.getLogger('Avispa')
        self.lggr = AvispaLoggerAdapter(logger, {'tid': tid,'ip': ip})

        self.collectionprotocols = {}
        self.collectionprotocols['collectionprotocol'] = ['CollectioNname','CollectionDescription','CollectionVersion']
        self.collectionprotocols['mandatory'] = ['CollectionName']
        self.collectionprotocols['defaults'] = {'CollectionVersion':'0.1.0'}
        self.COM = CollectionsModel()
   
    def post_a_x(self,rqform,handle):
               
        if 'CollectionName' in rqform:
            collectiond = {}
            collectiond['name'] = rqform.get('CollectionName').lower() # I dont like this here
            collectiond['handle'] = handle.lower()

            if 'CollectionDescription' in rqform:
                collectiond['description'] = rqform.get('CollectionDescription').lower()
            else:
                collectiond['description'] = ''     
            if rqform.get('CollectionVersion'):
                collectiond['version'] = rqform.get('CollectionVersion').replace('.','-') # I dont like this here
            else:
                collectiond['version'] = self.collectionprotocols['defaults']['CollectionVersion'].replace('.','-')
            
            ringlist = []
          
            for p in rqform:
                pparts = p.split('_')
                ring = {}
                if pparts[0] == 'ring' and pparts[1]:
                    value = rqform.get(p)
                    vparts = value.split('_')
                    ring['handle'] = vparts[0]
                    ring['ringname'] = '_'.join(vparts[1:])
                    # Will implement this later. Layer is to separate from primary and secondary rings
                    ring['layer'] = 1 
                    ringlist.append(ring)

            collectiond['ringlist'] = ringlist
               
            #Here you write to the user.collection document
                     
            if self.COM.post_a_x(handle,collectiond):
                self.lggr.debug('New Collection created: '+collectiond['name'])
                return True
            else:
                self.lggr.debug('The Collection '+ collectiond['name'] +' database already exists')
                return False

    def put_a_x_y(self,rqform,handle,collection):

        #Same as collectiongenerator
        if rqform.get('CollectionName'):

            collectiond = {}

            collectiond['name'] = rqform.get('CollectionName').lower() # I dont like this here
            collectiond['description'] = rqform.get('CollectionDescription').lower()
            collectiond['handle'] = handle.lower()
            if rqform.get('CollectionVersion'):
                collectiond['version'] = rqform.get('CollectionVersion').replace('.','-') # I dont like this here
            
            
            ringlist = []
          
            for p in rqform:
                pparts = p.split('_')
                ring = {}
                if pparts[0] == 'ring' and pparts[1]:
                    value = rqform.get(p)
                    vparts = value.split('_')
                    ring['handle'] = vparts[0]
                    ring['ringname'] = '_'.join(vparts[1:])
                    # Will implement layer later. This is to separate from primary and secondary rings
                    ring['layer'] = 1 
                    ringlist.append(ring)

            collectiond['ringlist'] = ringlist
                        
            if self.COM.put_a_x_y(handle,collectiond):
                self.lggr.debug('Collection updated: '+collectiond['name'])
                return True
            else:
                self.lggr.debug('The Collection '+ collectiond['name'] +' database already exists')
                return False
class CollectionsController:
    def __init__(self, tid=None, ip=None):

        logger = logging.getLogger('Avispa')
        self.lggr = AvispaLoggerAdapter(logger, {'tid': tid, 'ip': ip})

        self.RIM = RingsModel(tid=tid, ip=ip)
        self.COM = CollectionsModel(tid=tid, ip=ip)
        self.CB = CollectionBuilder(tid=tid, ip=ip)

    # GET/a
    def get_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        'Show list of collections'

        collectionlist = self.COM.get_a_x(handle)

        count = 0
        if collectionlist:
            for collection in collectionlist:
                count = count + 1
        else:
            collectionlist = []

        collectionlistlen = count

        #raise Exception("Debug")

        d = {
            'template': 'avispa_rest/get_a_x.html',
            'collectionlist': collectionlist,
            'collectionlistlen': collectionlistlen
        }
        return d

    def get_rq_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection get_rq_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def get_rs_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection get_rs_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def get_q_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection get_q_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    # POST/a
    def post_a_x(self,
                 handle,
                 collection,
                 idx,
                 api=False,
                 rqform=None,
                 *args,
                 **kargs):

        #Build the actual collection

        result = self.CB.post_a_x(rqform, handle)

        if result:
            self.lggr.debug('Awesome , you just created a new Collection')
            #msg = 'Item put with id: '+idx

            if api:
                out = {}
                out['Success'] = True
                out['Message'] = 'The collection has been created'
                d = {}
                d['api_out'] = json.dumps(out)
                d['template'] = '/base_json.html'

            else:
                flash("Your new Collection has been created", 'UI')
                #redirect = '/'+handle
                redirect = url_for('avispa_rest.home',
                                   handle=handle,
                                   _external=True,
                                   _scheme=URL_SCHEME)

                d = {'redirect': redirect, 'status': 200}

        else:

            if api:
                out = {}
                out['Sucess'] = False
                out['Message'] = 'There was an error creating the Collection'
                data = {}
                data['api_out'] = json.dumps(out)
                d['template'] = '/base_json.html'

            else:
                flash("There was an error creating the Collection", 'UI')

        return d

    def post_rq_a_x(self, handle, collection, idx, api=False, *args, **kargs):

        #Generates de form to create the collection

        ringlist = self.RIM.user_get_rings(handle)

        d = {
            'message': 'Using Collection post_rq_a_x for handle ' + handle,
            'template': 'avispa_rest/post_rq_a_x.html',
            'ringlist': ringlist
        }
        return d

    def post_rs_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection post_rs_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    #PUT /a
    def put_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection put_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def put_rq_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection put_rq_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def put_rs_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection put_rs_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    #PATCH /a
    def patch_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection patch_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def patch_rq_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection patch_rq_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def patch_rs_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection patch_rs_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    #DELETE /a
    def delete_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection delete_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def delete_rq_a_x(self,
                      handle,
                      collection,
                      idx,
                      api=False,
                      *args,
                      **kargs):
        d = {
            'message': 'Using Collection delete_rq_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def delete_rs_a_x(self,
                      handle,
                      collection,
                      idx,
                      api=False,
                      *args,
                      **kargs):
        d = {
            'message': 'Using Collection delete_rs_a for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    #SEARCH /a
    def search_a_x(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection search_a for handle ' + handle,
            'template': 'avispa_rest/search_a.html'
        }
        return d

    def search_rq_a_x(self,
                      handle,
                      collection,
                      idx,
                      api=False,
                      *args,
                      **kargs):
        d = {
            'message': 'Using Collection search_rq_a for handle ' + handle,
            'template': 'avispa_rest/search_rq_a.html'
        }
        return d

    # /a/b

    #GET /a/x/y
    def get_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        #THIS IS NOT USED . SEE CollectionsController.put_rq_a_x_y() instead

        d = {
            'message': 'Using Collection get_a_x_y for handle ' + handle,
            'template': 'avispa_rest/get_a.html'
        }
        return d

    def get_rq_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message':
            'Using Collection get_rq_a_x_y for handle:' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    def get_rs_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message':
            'Using Collection get_rs_a_x_y for handle:' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    #POST /a/x/y
    def post_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message': 'Using Collection post_a_x_y for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def post_rq_a_x_y(self,
                      handle,
                      collection,
                      idx,
                      api=False,
                      *args,
                      **kargs):
        d = {
            'message': 'Using Collection post_rq_a_x_y for handle ' + handle,
            'template': 'avispa_rest/index.html'
        }
        return d

    def post_rs_a_x_y(self,
                      handle,
                      collection,
                      idx,
                      api=False,
                      *args,
                      **kargs):
        d = {
            'message':
            'Using Collection post_rs_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    #PUT /a/x/y
    def put_a_x_y(self,
                  handle,
                  collection,
                  idx,
                  api=False,
                  rqform=None,
                  *args,
                  **kargs):
        # Introduce the changes to the existing collection

        CB = CollectionBuilder()
        result = CB.put_a_x_y(rqform, handle, collection)

        if result:
            self.lggr.debug('Awesome , you just updated a Collection')
            #msg = 'Item put with id: '+idx
            flash("Your Collection has been updated", 'UI')

            redirect = url_for('avispa_rest.home',
                               handle=handle,
                               _external=True,
                               _scheme=URL_SCHEME)

            d = {'redirect': redirect, 'status': 200}

        else:
            d = {
                'message': 'There was an error updating the collection',
                'template': 'avispa_rest/index.html'
            }

        return d

    def put_rq_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        #Form to edit a collection
        ringlist = self.RIM.user_get_rings(handle)
        collectiond = self.COM.get_a_x_y(
            handle, collection)  #It comes with just one collection

        collectionrings = []
        for ring in collectiond['rings']:
            collectionrings.append(ring['handle'] + '_' + ring['ringname'])

        d = {
            'message': 'Using Collection put_rq_a_x_y for handle ' + handle,
            'template': 'avispa_rest/put_rq_a_x_y.html',
            'ringlist': ringlist,
            'collectionlist': collectiond,
            'collectionrings': collectionrings
        }

        #raise Exception('debug')

        #[u'blacklabelrobot_tricoders_0.1.0', u'blacklabelrobot_pancreas_0.1.0', u'blacklabelrobot_intestino_0.1.0', u'blacklabelrobot_tricoders4_']

        return d

    def put_rs_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message':
            'Using Collection put_rs_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    #PATCH /a/x/y
    def patch_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message':
            'Using Collection patch_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    def patch_rq_a_x_y(self,
                       handle,
                       collection,
                       idx,
                       api=False,
                       *args,
                       **kargs):
        d = {
            'message':
            'Using Collection patch_rq_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    def patch_rs_a_x_y(self,
                       handle,
                       collection,
                       idx,
                       api=False,
                       *args,
                       **kargs):
        d = {
            'message':
            'Using Collection patch_rs_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    #DELETE /a/x/y
    def delete_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        #Will delete an existing collection

        result = self.COM.delete_a_x_y(handle, collection)

        if result:
            self.lggr.debug('Awesome , you just deleted a Collection')
            #msg = 'Item put with id: '+idx
            flash("Your Collection has been deleted", 'UI')
            #redirect = '/'+handle
            redirect = url_for('avispa_rest.home',
                               handle=handle,
                               _external=True,
                               _scheme=URL_SCHEME)

            d = {'redirect': redirect, 'status': 200}

        else:
            d = {
                'message': 'There was an error deleting the collection',
                'template': 'avispa_rest/index.html'
            }

        return d

    def delete_rq_a_x_y(self,
                        handle,
                        collection,
                        idx,
                        api=False,
                        *args,
                        **kargs):
        d = {
            'message':
            'Using Collection delete_rq_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    def delete_rs_a_x_y(self,
                        handle,
                        collection,
                        idx,
                        api=False,
                        *args,
                        **kargs):
        d = {
            'message':
            'Using Collection delete_rs_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/index.html'
        }
        return d

    #SEARCH /a/b
    def search_a_x_y(self, handle, collection, idx, api=False, *args, **kargs):
        d = {
            'message':
            'Using Collection search_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/search_a_b.html'
        }
        return d

    def search_rq_a_x_y(self,
                        handle,
                        collection,
                        idx,
                        api=False,
                        *args,
                        **kargs):
        d = {
            'message':
            'Using Collection search_rq_a_x_y for handle ' + handle +
            ', collection:' + collection,
            'template':
            'avispa_rest/search_rq_a_b.html'
        }
        return d