Пример #1
0
def submitAlephRecordsLoad(wfStateInfo):
    logger.info("submitAlephRecordsLoad")
    print "submit aleph records load"
    wft = api.portal.get_tool('portal_workflow')
    epublication = wfStateInfo.object
    systemMessages = epublication['system-messages']
    originalFiles = epublication['original-files']
    isbns = frozenset([ii.isbn for ii in originalFiles.results() if ii.isbn])

    logger.info("submitSearchRequest")
    producer = getUtility(IProducer, name="amqp.isbn-search-request")
    with api.env.adopt_user(username="******"):
        for isbn in isbns:
            isbnq = ISBNQuery(isbn)
            request = SearchRequest(isbnq)
            producer.publish(serialize(request),
                             content_type = 'application/json',
                             headers = \
                             {'UUID': json.dumps({ \
                                                   'type': 'edeposit.epublication-load-aleph-records',
                                                   'value': { 'context_UID': str(epublication.UID()), 
                                                              'UID': 'search sysnumber for::' + isbn,
                                                          }
                                               })
                          }
            )
            wft.doActionFor(epublication, 'notifySystemAction', comment="Načtení záznamů z Alephu pro: " + isbn,)
            pass
        pass
Пример #2
0
def addedISBNValidateRequest(context, event):
    wft = api.portal.get_tool('portal_workflow')
    systemMessages = aq_parent(aq_inner(context))
    epublication = aq_parent(aq_inner(systemMessages))
    request = ISBNValidationRequest(context.isbn)
    producer = getUtility(IProducer, name="amqp.isbn-validate-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = {'UUID': json.dumps({'request_UID': str(context.UID()),
                                                    'systemMessages_UID': str(systemMessages.UID())
                                                })
                            }
                 )
    context.sent = datetime.now()
    wft.doActionFor(epublication, 'notifySystemAction', comment=context.title)
    return
def submitSearchRequest(wfStateInfo):
    logger.info("submitSearchRequest")
    context = wfStateInfo.object
    isbnq = ISBNQuery(context.isbn)
    request = SearchRequest(isbnq)
    producer = getUtility(IProducer, name="amqp.isbn-search-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = \
                     {'UUID': json.dumps({ \
                                           'type': 'edeposit.originalfile-search-alephrecords-request',
                                           'value': { 'context_UID': str(context.UID()), 
                                                      'UID': 'search-isbn:' + context.isbn
                                                 }
                                       })
                  }
                 )
def submitSearchRequest(wfStateInfo):
    logger.info("submitSearchRequest")
    context = wfStateInfo.object
    isbnq = ISBNQuery(context.isbn)
    request = SearchRequest(isbnq)
    producer = getUtility(IProducer, name="amqp.isbn-search-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = \
                     {'UUID': json.dumps({ \
                                           'type': 'edeposit.originalfile-search-alephrecords-request',
                                           'value': { 'context_UID': str(context.UID()),
                                                      'UID': 'search-isbn:' + context.isbn
                                                 }
                                       })
                  }
                 )
def loadAnEPublication(wfStateInfo):
    logger.info("load an ePublication")
    context = wfStateInfo.object
    aleph_record = context.choosen_aleph_record.to_object
    doc_id = aleph_record.aleph_sys_number
    library = aleph_record.aleph_library
    request = SearchRequest(DocumentQuery(doc_id=doc_id, library=library))
    producer = getUtility(IProducer, name="amqp.sysnumber-search-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = \
                     {'UUID': json.dumps({ \
                                           'type': 'edeposit.originalfile-load-epublication-request',
                                           'value': { 'context_UID': str(context.UID()), 
                                                      'UID': 'search-sysnumber:' + str(doc_id) + "/" + str(library)
                                                  }
                                       })
                  }
                 )
def loadAnEPublication(wfStateInfo):
    logger.info("load an ePublication")
    context = wfStateInfo.object
    aleph_record = context.choosen_aleph_record.to_object
    doc_id = aleph_record.aleph_sys_number
    library = aleph_record.aleph_library
    request = SearchRequest(DocumentQuery(doc_id=doc_id, library=library))
    producer = getUtility(IProducer, name="amqp.sysnumber-search-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = \
                     {'UUID': json.dumps({ \
                                           'type': 'edeposit.originalfile-load-epublication-request',
                                           'value': { 'context_UID': str(context.UID()),
                                                      'UID': 'search-sysnumber:' + str(doc_id) + "/" + str(library)
                                                  }
                                       })
                  }
                 )
    def body(self):
        """
        This method handles AMQP connection details and reacts to FTP events by
        sending messages to output queue.
        """
        self.connection = pika.BlockingConnection(self.connection_param)
        self.channel = self.connection.channel()

        print "Monitoring file '%s'." % self.ftp_extended_log

        file_iter = process_log(
            sh.tail("-f", self.ftp_extended_log, _iter=True)
        )
        for import_request in file_iter:
            self.sendMessage(
                exchange=self.output_exchange,
                routing_key=self.output_key,
                message=serializers.serialize(import_request),
                UUID=str(uuid.uuid1())
            )
Пример #8
0
def addedAlephExportRequest(context, event):
    wft = api.portal.get_tool('portal_workflow')
    systemMessages = aq_parent(aq_inner(context))
    epublication = aq_parent(aq_inner(systemMessages))
    originalFile = epublication[context.originalFileID]
    authors = map(lambda aa: Author(lastName = aa.fullname, firstName="", title = ""), epublication.authors.results())
    epublicationRecord =  EPublicationExport (
        ISBN = originalFile.isbn or "",
        nazev = epublication.title or "",
        podnazev = epublication.podnazev or "",
        vazba = "online",
        cena = str(epublication.cena or ""),
        castDil = epublication.cast or "",
        nazevCasti = epublication.nazev_casti or "",
        nakladatelVydavatel = epublication.nakladatel_vydavatel or "",
        datumVydani = str(epublication.rok_vydani),
        poradiVydani = epublication.poradi_vydani or "",
        zpracovatelZaznamu = originalFile.zpracovatel_zaznamu or "",
        format = originalFile.format or "",
        url = originalFile.url or "",
        mistoVydani = epublication.misto_vydani,
        ISBNSouboruPublikaci = epublication.isbn_souboru_publikaci or "",
        autori = map(lambda author: author.lastName, filter(lambda author: author.lastName, authors)),
        originaly = [],
        internal_url = originalFile.absolute_url() or "",
    )

    request = ExportRequest(epublication=epublicationRecord)
    producer = getUtility(IProducer, name="amqp.aleph-export-request")
    producer.publish(serialize(request),
                     content_type = 'application/json',
                     headers = {'UUID': json.dumps({'request_UID': str(context.UID()),
                                                    'systemMessages_UID': str(systemMessages.UID())
                                                })
                            }
                 )
    context.sent = datetime.now()
    wft.doActionFor(epublication, 'exportToAlephSubmitted')
    return
Пример #9
0
#
# Interpreter version: python 2.7
#
# Imports =====================================================================
import os
import json

from aleph import *
import edeposit.amqp.serializers as serializers

from test_daemons import CMD, SH_CMD, create_commands


# Variables ===================================================================
ALEPH_TEST_OK = serializers.serialize(
    SearchRequest(ISBNQuery("80-251-0225-4"))
)


# Functions & objects =========================================================
def setup_module():
    create_commands()
    SH_CMD["alephdaemon"]("stop")

    # there are serious tty problems with sh module and DaemonWrapper, thats why
    os.system(CMD["alephdaemon"] + " start")


def parse_data(data):
    spacer = "-" * 79
    out = data.split(spacer)[-2]
Пример #10
0
 def encode(self):
     return serialize(self.context)
#!/usr/bin/python

import pika
import argparse
import datetime
from edeposit.amqp.aleph_link_export import StatusRequest
from edeposit.amqp.serializers import serialize

"""
(project-shell "*shell*" "/usr/bin")
(project-task send-amqp-aleph-link-exportd "*shell*" "send-amqp-aleph-link-exportd-tick.py")

(local-set-key (kbd "C-c C-c") 'send-amqp-aleph-link-exportd)
(local-set-key (kbd "C-c l") 'send-current-line-to-shell)
"""

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Send message to RabbitMQ to update status at Aleph Link Exportd")
    pargs = parser.parse_args()
    conn = pika.BlockingConnection(pika.URLParameters("http://*****:*****@localhost:5672/aleph"))
    channel = conn.channel()
    request=StatusRequest()
    channel.basic_publish("update-links", "tick", serialize(request), 
                          pika.BasicProperties(content_type="application/json",
                                               headers=dict(UUID=str(datetime.datetime.now())),
                                               delivery_mode=2))