IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2009, 5:54:55 PM (17 years ago)
Author:
Paul Price
Message:

Distribution client workflow is now working!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/receivetool.c

    r23885 r23894  
    9595
    9696    // required
    97     PXOPT_LOOKUP_STR(source, config->args, "-stage", true, false);
     97    PXOPT_LOOKUP_STR(source, config->args, "-source", true, false);
    9898    PXOPT_LOOKUP_STR(product, config->args, "-product",  true, false);
     99    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
    99100
    100101    // optional
    101     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
    102102    PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
    103103    PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
     
    168168
    169169    // required
    170     PXOPT_LOOKUP_S64(source_id, config->args, "-source_id", true, false);
    171     PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
    172 
    173     if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset)) {
     170    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
     171    psMetadataItem *filesets = psMetadataLookup(config->args, "-fileset");
     172    if (!filesets) {
     173        psError(PS_ERR_UNKNOWN, true, "-fileset is required");
     174        return false;
     175    }
     176
     177    if (!psDBTransaction(config->dbh)) {
     178        psError(PS_ERR_UNKNOWN, false, "Database error");
     179        return false;
     180    }
     181
     182    psListIterator *iter = psListIteratorAlloc(filesets->data.list, PS_LIST_HEAD, false); // Iterator
     183    psMetadataItem *item = NULL;        // Item from iteration
     184    while ((item = psListGetAndIncrement(iter))) {
     185        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
     186
     187        if (!receiveFilesetInsert(config->dbh, 0, source_id, item->data.str)) {
     188            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
     189            if (!psDBTransaction(config->dbh)) {
     190                psError(PS_ERR_UNKNOWN, false, "Database error");
     191                return false;
     192            }
     193            psFree(iter);
     194            return false;
     195        }
     196    }
     197    psFree(iter);
     198
     199    if (!psDBCommit(config->dbh)) {
    174200        psError(PS_ERR_UNKNOWN, false, "Database error");
    175201        return false;
     
    184210
    185211    // required
    186     PXOPT_LOOKUP_S64(source_id, config->args, "-source_id", true, false);
     212    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
    187213    PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
    188214
     
    212238    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
    213239    PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
     240
     241    // optional
     242    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     243    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    214244
    215245    psString query = pxDataGet("receivetool_pendingfileset.sql");
     
    227257    psFree(where);
    228258
     259    if (limit) {
     260        psString limitString = psDBGenerateLimitSQL(limit);
     261        psStringAppend(&query, " %s", limitString);
     262        psFree(limitString);
     263    }
     264
    229265    if (!p_psDBRunQueryF(config->dbh, query)) {
    230266        psError(PS_ERR_UNKNOWN, false, "Database error");
     
    244280        return true;
    245281    }
    246     if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", true)) {
     282    if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", !simple)) {
    247283        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    248284        psFree(output);
     
    260296    // required
    261297    PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
    262     PXOPT_LOOKUP_STR(file, config->args, "-file",  true, false);
    263 
    264     if (!receiveFileInsert(config->dbh, 0, fileset_id, file)) {
     298    psMetadataItem *files = psMetadataLookup(config->args, "-file");
     299    if (!files) {
     300        psError(PS_ERR_UNKNOWN, true, "-file is required");
     301        return false;
     302    }
     303
     304    if (!psDBTransaction(config->dbh)) {
     305        psError(PS_ERR_UNKNOWN, false, "Database error");
     306        return false;
     307    }
     308
     309    psListIterator *iter = psListIteratorAlloc(files->data.list, PS_LIST_HEAD, false); // Iterator
     310    psMetadataItem *item = NULL;        // Item from iteration
     311    while ((item = psListGetAndIncrement(iter))) {
     312        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
     313
     314        if (!receiveFileInsert(config->dbh, 0, fileset_id, item->data.str)) {
     315            psError(PS_ERR_UNKNOWN, false, "Unable to add file");
     316            if (!psDBTransaction(config->dbh)) {
     317                psError(PS_ERR_UNKNOWN, false, "Database error");
     318                return false;
     319            }
     320            psFree(iter);
     321            return false;
     322        }
     323    }
     324    psFree(iter);
     325
     326    if (!psDBCommit(config->dbh)) {
    265327        psError(PS_ERR_UNKNOWN, false, "Database error");
    266328        return false;
     
    282344    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.file_id", "==");
    283345
     346    // optional
     347    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     348    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     349
    284350    psString query = pxDataGet("receivetool_pendingfile.sql");
    285351    if (!query) {
     
    296362    psFree(where);
    297363
     364    if (limit) {
     365        psString limitString = psDBGenerateLimitSQL(limit);
     366        psStringAppend(&query, " %s", limitString);
     367        psFree(limitString);
     368    }
     369
    298370    if (!p_psDBRunQueryF(config->dbh, query)) {
    299371        psError(PS_ERR_UNKNOWN, false, "Database error");
     
    313385        return true;
    314386    }
    315     if (!ippdbPrintMetadatas(stdout, output, "receiveFile", true)) {
     387    if (!ippdbPrintMetadatas(stdout, output, "receiveFile", !simple)) {
    316388        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    317389        psFree(output);
     
    328400
    329401    // required
    330     PXOPT_LOOKUP_S64(fileset_id, config->args, "-source_id", true, false);
     402    PXOPT_LOOKUP_S64(file_id, config->args, "-file_id", true, false);
    331403
    332404    // optional
     
    335407    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
    336408
    337     if (!receiveResultInsert(config->dbh, fileset_id, dtime_copy, dtime_extract, fault)) {
     409    if (!receiveResultInsert(config->dbh, file_id, dtime_copy, dtime_extract, fault)) {
    338410        psError(PS_ERR_UNKNOWN, false, "Database error");
    339411        return false;
Note: See TracChangeset for help on using the changeset viewer.