IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 20, 2015, 12:32:54 PM (11 years ago)
Author:
bills
Message:

Add 3 new postage stamp tables to the IPP database config.
Note that we don't keep the postage stamp tables in the gpc1 database
so there are no changes listed in dbconfig/changes.txt to update them.
We do that to avoid mistakenly using pstamptool without setting the dbserver to
the system that actually hosts the ippRequestServer database (currently ippc17).

File:
1 edited

Legend:

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

    r38134 r38157  
    6161static bool deletefileMode(pxConfig *config);
    6262
     63static bool adddomainMode(pxConfig * config);
     64static bool updatedomainMode(pxConfig * config);
    6365static bool listdomainMode(pxConfig *config);
     66static bool adduserMode(pxConfig * config);
     67static bool updateuserMode(pxConfig * config);
    6468static bool listuserMode(pxConfig * config);
     69static bool addaccesslevelMode(pxConfig * config);
     70static bool updateaccesslevelMode(pxConfig * config);
     71static bool listaccesslevelMode(pxConfig * config);
    6572
    6673# define MODECASE(caseName, func) \
     
    114121        MODECASE(PSTAMPTOOL_MODE_DELETEFILE, deletefileMode);
    115122
     123        MODECASE(PSTAMPTOOL_MODE_ADDDOMAIN, adddomainMode);
     124        MODECASE(PSTAMPTOOL_MODE_UPDATEDOMAIN, updatedomainMode);
    116125        MODECASE(PSTAMPTOOL_MODE_LISTDOMAIN, listdomainMode);
     126        MODECASE(PSTAMPTOOL_MODE_ADDUSER, adduserMode);
     127        MODECASE(PSTAMPTOOL_MODE_UPDATEUSER, updateuserMode);
    117128        MODECASE(PSTAMPTOOL_MODE_LISTUSER, listuserMode);
     129        MODECASE(PSTAMPTOOL_MODE_ADDACCESSLEVEL, addaccesslevelMode);
     130        MODECASE(PSTAMPTOOL_MODE_UPDATEACCESSLEVEL, updateaccesslevelMode);
     131        MODECASE(PSTAMPTOOL_MODE_LISTACCESSLEVEL, listaccesslevelMode);
    118132
    119133        default:
     
    17091723}
    17101724
     1725static bool adddomainMode(pxConfig *config)
     1726{
     1727    PS_ASSERT_PTR_NON_NULL(config, false);
     1728
     1729    PXOPT_LOOKUP_STR(domainName,      config->args, "-domain",  true, false);
     1730    PXOPT_LOOKUP_S32(accessLevel,     config->args, "-accessLevel", true, false);
     1731    PXOPT_LOOKUP_STR(defaultProduct,  config->args, "-defaultProduct",  false, false);
     1732    PXOPT_LOOKUP_STR(defaultLabel,    config->args, "-defaultLabel",  false, false);
     1733
     1734    if (!pstampUserDomainInsert(config->dbh,
     1735        domainName,
     1736        accessLevel,
     1737        defaultProduct,
     1738        defaultLabel
     1739        )) {
     1740        psError(PS_ERR_UNKNOWN, false, "failed to insert domain");
     1741        return false;
     1742    }
     1743
     1744    return true;
     1745}
     1746static bool updatedomainMode(pxConfig *config)
     1747{
     1748    PS_ASSERT_PTR_NON_NULL(config, false);
     1749
     1750    PXOPT_LOOKUP_STR(domainName,      config->args, "-domain",  true, false);
     1751    PXOPT_LOOKUP_S32(accessLevel,     config->args, "-accessLevel", false, false);
     1752    PXOPT_LOOKUP_STR(defaultProduct,  config->args, "-defaultProduct",  false, false);
     1753    PXOPT_LOOKUP_STR(defaultLabel,    config->args, "-defaultLabel",  false, false);
     1754
     1755    if (!accessLevel && !defaultProduct && !defaultLabel) {
     1756        psError(PS_ERR_UNKNOWN, true, "at least one set option is required");
     1757        return false;
     1758    }
     1759
     1760    psMetadata *where = psMetadataAlloc();
     1761    PXOPT_COPY_STR(config->args, where, "-domain",   "domainName", "==");
     1762    if (!psListLength(where->list)) {
     1763        psFree(where);
     1764        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1765        return false;
     1766    }
     1767
     1768    psString query = psStringCopy("UPDATE pstampUserDomain SET");
     1769
     1770    char * sep = "";
     1771    if (accessLevel) {
     1772        psStringAppend(&query, "%s accessLevel = '%d'", sep, accessLevel);
     1773        sep = ", ";
     1774    }
     1775    if (defaultProduct) {
     1776        psStringAppend(&query, "%s  defaultProduct = '%s'", sep, defaultProduct);
     1777        sep = ", ";
     1778    }
     1779    if (defaultLabel) {
     1780        psStringAppend(&query, "%s defaultLabel = '%s'", sep, defaultLabel);
     1781        sep = ", ";
     1782    }
     1783
     1784    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1785    psStringAppend(&query, "\nWHERE %s", whereClause);
     1786    psFree(whereClause);
     1787    psFree(where);
     1788
     1789    if (!p_psDBRunQuery(config->dbh, query)) {
     1790        psError(PS_ERR_UNKNOWN, false, "database error");
     1791        psFree(query);
     1792        return false;
     1793    }
     1794
     1795    // psU64 affected = psDBAffectedRows(config->dbh);
     1796    // psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampRequests", affected);
     1797
     1798    return true;
     1799}
     1800
    17111801static bool listdomainMode(pxConfig *config)
    17121802{
     
    17151805    psMetadata *where = psMetadataAlloc();
    17161806    PXOPT_COPY_STR(config->args, where, "-domain", "domainName", "=");
    1717     PXOPT_COPY_S32(config->args, where, "-access_level", "accessLevel", "=");
     1807    PXOPT_COPY_S32(config->args, where, "-accessLevel", "accessLevel", "=");
    17181808
    17191809    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    17641854    return true;
    17651855}
     1856static bool adduserMode(pxConfig *config)
     1857{
     1858    PS_ASSERT_PTR_NON_NULL(config, false);
     1859
     1860    PXOPT_LOOKUP_STR(userName,        config->args, "-user",  true, false);
     1861    PXOPT_LOOKUP_STR(domainName,      config->args, "-domain",  true, false);
     1862    PXOPT_LOOKUP_S32(accessLevel,     config->args, "-accessLevel", false, false);
     1863    PXOPT_LOOKUP_STR(defaultProduct,  config->args, "-defaultProduct",  false, false);
     1864    PXOPT_LOOKUP_STR(defaultLabel,    config->args, "-defaultLabel",  false, false);
     1865
     1866    if (!pstampUserInsert(config->dbh,
     1867        userName,
     1868        domainName,
     1869        accessLevel,
     1870        defaultProduct,
     1871        defaultLabel
     1872        )) {
     1873        psError(PS_ERR_UNKNOWN, false, "failed to insert user");
     1874        return false;
     1875    }
     1876
     1877    return true;
     1878}
     1879static bool updateuserMode(pxConfig *config)
     1880{
     1881    PS_ASSERT_PTR_NON_NULL(config, false);
     1882
     1883    PXOPT_LOOKUP_STR(userName,        config->args, "-user",  true, false);
     1884    PXOPT_LOOKUP_STR(domainName,      config->args, "-domain",  true, false);
     1885    PXOPT_LOOKUP_S32(accessLevel,     config->args, "-accessLevel", false, false);
     1886    PXOPT_LOOKUP_STR(defaultProduct,  config->args, "-defaultProduct",  false, false);
     1887    PXOPT_LOOKUP_STR(defaultLabel,    config->args, "-defaultLabel",  false, false);
     1888
     1889    if (!accessLevel && !defaultProduct && !defaultLabel) {
     1890        psError(PS_ERR_UNKNOWN, true, "at least one set option is required");
     1891        return false;
     1892    }
     1893
     1894    psMetadata *where = psMetadataAlloc();
     1895    PXOPT_COPY_STR(config->args, where, "-user",     "userName", "==");
     1896    PXOPT_COPY_STR(config->args, where, "-domain",   "domainName", "==");
     1897    if (!psListLength(where->list)) {
     1898        psFree(where);
     1899        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     1900        return false;
     1901    }
     1902
     1903    psString query = psStringCopy("UPDATE pstampUser SET");
     1904
     1905    char * sep = "";
     1906    if (accessLevel) {
     1907        psStringAppend(&query, "%s accessLevel = '%d'", sep, accessLevel);
     1908        sep = ", ";
     1909    }
     1910    if (defaultProduct) {
     1911        psStringAppend(&query, "%s  defaultProduct = '%s'", sep, defaultProduct);
     1912        sep = ", ";
     1913    }
     1914    if (defaultLabel) {
     1915        psStringAppend(&query, "%s defaultLabel = '%s'", sep, defaultLabel);
     1916        sep = ", ";
     1917    }
     1918
     1919    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1920    psStringAppend(&query, "\nWHERE %s", whereClause);
     1921    psFree(whereClause);
     1922    psFree(where);
     1923
     1924    if (!p_psDBRunQuery(config->dbh, query)) {
     1925        psError(PS_ERR_UNKNOWN, false, "database error");
     1926        psFree(query);
     1927        return false;
     1928    }
     1929
     1930    // psU64 affected = psDBAffectedRows(config->dbh);
     1931    // psLogMsg("pstamptool", PS_LOG_INFO, "Updated %" PRIu64 " pstampRequests", affected);
     1932
     1933    return true;
     1934}
    17661935static bool listuserMode(pxConfig *config)
    17671936{
     
    17711940    PXOPT_COPY_STR(config->args, where, "-user", "userName", "=");
    17721941    PXOPT_COPY_STR(config->args, where, "-domain", "domainName", "=");
    1773     PXOPT_COPY_S32(config->args, where, "-access_level", "pstampUser.accessLevel", "=");
     1942    PXOPT_COPY_S32(config->args, where, "-accessLevel", "pstampUser.accessLevel", "=");
    17741943    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    17751944    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    18221991    return true;
    18231992}
     1993
     1994static bool addaccesslevelMode(pxConfig *config)
     1995{
     1996    PS_ASSERT_PTR_NON_NULL(config, false);
     1997
     1998    PXOPT_LOOKUP_S64(proj_id,         config->args, "-proj_id", false, false);
     1999    PXOPT_LOOKUP_STR(project_name,    config->args, "-project_name",  false, false);
     2000    PXOPT_LOOKUP_S32(accessLevel,     config->args, "-accessLevel", true, false);
     2001    PXOPT_LOOKUP_F32(mjd_min,         config->args, "-mjd_min", false, false);
     2002    PXOPT_LOOKUP_F32(mjd_max,         config->args, "-mjd_max", false, false);
     2003
     2004    if (proj_id) {
     2005        if (!pstampAccessLevelInsert(config->dbh,
     2006            proj_id,
     2007            accessLevel,
     2008            mjd_min,
     2009            mjd_max
     2010        )) {
     2011            psError(PS_ERR_UNKNOWN, false, "failed to insert accessLevel");
     2012            return false;
     2013        }
     2014    } else if (project_name) {
     2015        // use select insert getting proj_id from pstampProject
     2016        psString query = pxDataGet("pstamptool_addaccesslevel.sql");
     2017        if (!p_psDBRunQueryF(config->dbh, query, accessLevel, mjd_min, mjd_max, project_name)) {
     2018            psError(PS_ERR_UNKNOWN, false, "database error");
     2019            psFree(query);
     2020            return false;
     2021        }
     2022        psFree(query);
     2023    } else {
     2024        psError(PS_ERR_UNKNOWN, true, "proj_id or project_name is required");
     2025        return false;
     2026    }
     2027
     2028    return true;
     2029}
     2030static bool updateaccesslevelMode(pxConfig *config)
     2031{
     2032    return false;
     2033}
     2034static bool listaccesslevelMode(pxConfig *config)
     2035{
     2036    PS_ASSERT_PTR_NON_NULL(config, false);
     2037
     2038    psMetadata *where = psMetadataAlloc();
     2039    PXOPT_COPY_STR(config->args, where, "-project_name", "pstampProject.name", "=");
     2040    PXOPT_COPY_S64(config->args, where, "-proj_id", "proj_id", "=");
     2041    PXOPT_COPY_S32(config->args, where, "-accessLevel", "accessLevel", "=");
     2042
     2043    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     2044    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     2045
     2046    psString query = psStringCopy("SELECT * from pstampAccessLevel join pstampProject USING(proj_id)");
     2047
     2048    if (psListLength(where->list)) {
     2049        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     2050        psStringAppend(&query, " WHERE %s", whereClause);
     2051        psFree(whereClause);
     2052    }
     2053    psFree(where);
     2054
     2055    // treat limit == 0 as "no limit"
     2056    if (limit) {
     2057        psString limitString = psDBGenerateLimitSQL(limit);
     2058        psStringAppend(&query, " %s", limitString);
     2059        psFree(limitString);
     2060    }
     2061
     2062    if (!p_psDBRunQuery(config->dbh, query)) {
     2063        psError(PS_ERR_UNKNOWN, false, "database error");
     2064        psFree(query);
     2065        return false;
     2066    }
     2067    psFree(query);
     2068
     2069    psArray *output = p_psDBFetchResult(config->dbh);
     2070    if (!output) {
     2071        psError(PS_ERR_UNKNOWN, false, "database error");
     2072        return false;
     2073    }
     2074    if (!psArrayLength(output)) {
     2075        psFree(output);
     2076        return true;
     2077    }
     2078
     2079    // negative simple so the default is true
     2080    if (!ippdbPrintMetadatas(stdout, output, "pstampAccessLevel", !simple)) {
     2081        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     2082        psFree(output);
     2083        return false;
     2084    }
     2085
     2086    psFree(output);
     2087
     2088    return true;
     2089}
    18242090# endif
Note: See TracChangeset for help on using the changeset viewer.