IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2015, 2:01:54 PM (11 years ago)
Author:
bills
Message:

Add functions to extract the contents of 3 new tables
pstampUser pstampUserDomain and pstampAccessLevel.

pstampUserDomain sets integer accessLevel value for users with email addresses from
the specified domain. For example ifa.hawaii.edu

pstampUser may be used to override the domains values for specific users. For example
mops@…

pstampAccessLevel has primary key(proj_id, accessLevel) and a set of date limits mjd_min and
mjd_max. We can use this to look up the range of dates that a user with a given accessLevel
may access for the given project. (gpc1, gpc2, etc)

File:
1 edited

Legend:

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

    r38009 r38134  
    6060static bool listfileMode(pxConfig *config);
    6161static bool deletefileMode(pxConfig *config);
     62
     63static bool listdomainMode(pxConfig *config);
     64static bool listuserMode(pxConfig * config);
    6265
    6366# define MODECASE(caseName, func) \
     
    110113        MODECASE(PSTAMPTOOL_MODE_LISTFILE, listfileMode);
    111114        MODECASE(PSTAMPTOOL_MODE_DELETEFILE, deletefileMode);
     115
     116        MODECASE(PSTAMPTOOL_MODE_LISTDOMAIN, listdomainMode);
     117        MODECASE(PSTAMPTOOL_MODE_LISTUSER, listuserMode);
    112118
    113119        default:
     
    17021708    return true;
    17031709}
     1710
     1711static bool listdomainMode(pxConfig *config)
     1712{
     1713    PS_ASSERT_PTR_NON_NULL(config, false);
     1714
     1715    psMetadata *where = psMetadataAlloc();
     1716    PXOPT_COPY_STR(config->args, where, "-domain", "domainName", "=");
     1717    PXOPT_COPY_S32(config->args, where, "-access_level", "accessLevel", "=");
     1718
     1719    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1720    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1721
     1722    psString query = psStringCopy("SELECT * from pstampUserDomain");
     1723
     1724    if (psListLength(where->list)) {
     1725        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1726        psStringAppend(&query, " WHERE %s", whereClause);
     1727        psFree(whereClause);
     1728    }
     1729    psFree(where);
     1730
     1731    // treat limit == 0 as "no limit"
     1732    if (limit) {
     1733        psString limitString = psDBGenerateLimitSQL(limit);
     1734        psStringAppend(&query, " %s", limitString);
     1735        psFree(limitString);
     1736    }
     1737
     1738    if (!p_psDBRunQuery(config->dbh, query)) {
     1739        psError(PS_ERR_UNKNOWN, false, "database error");
     1740        psFree(query);
     1741        return false;
     1742    }
     1743    psFree(query);
     1744
     1745    psArray *output = p_psDBFetchResult(config->dbh);
     1746    if (!output) {
     1747        psError(PS_ERR_UNKNOWN, false, "database error");
     1748        return false;
     1749    }
     1750    if (!psArrayLength(output)) {
     1751        psFree(output);
     1752        return true;
     1753    }
     1754
     1755    // negative simple so the default is true
     1756    if (!ippdbPrintMetadatas(stdout, output, "pstampUserDomain", !simple)) {
     1757        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1758        psFree(output);
     1759        return false;
     1760    }
     1761
     1762    psFree(output);
     1763
     1764    return true;
     1765}
     1766static bool listuserMode(pxConfig *config)
     1767{
     1768    PS_ASSERT_PTR_NON_NULL(config, false);
     1769
     1770    psMetadata *where = psMetadataAlloc();
     1771    PXOPT_COPY_STR(config->args, where, "-user", "userName", "=");
     1772    PXOPT_COPY_STR(config->args, where, "-domain", "domainName", "=");
     1773    PXOPT_COPY_S32(config->args, where, "-access_level", "pstampUser.accessLevel", "=");
     1774    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1775    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1776
     1777    if (!psListLength(where->list)) {
     1778        psError(PS_ERR_UNKNOWN, true, "search paramters are required");
     1779        return false;
     1780    }
     1781
     1782    psString query = pxDataGet("pstamptool_listuser.sql");
     1783
     1784    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1785    psStringAppend(&query, " WHERE %s", whereClause);
     1786    psFree(whereClause);
     1787    psFree(where);
     1788
     1789    // treat limit == 0 as "no limit"
     1790    if (limit) {
     1791        psString limitString = psDBGenerateLimitSQL(limit);
     1792        psStringAppend(&query, " %s", limitString);
     1793        psFree(limitString);
     1794    }
     1795
     1796    if (!p_psDBRunQuery(config->dbh, query)) {
     1797        psError(PS_ERR_UNKNOWN, false, "database error");
     1798        psFree(query);
     1799        return false;
     1800    }
     1801    psFree(query);
     1802
     1803    psArray *output = p_psDBFetchResult(config->dbh);
     1804    if (!output) {
     1805        psError(PS_ERR_UNKNOWN, false, "database error");
     1806        return false;
     1807    }
     1808    if (!psArrayLength(output)) {
     1809        psFree(output);
     1810        return true;
     1811    }
     1812
     1813    // negative simple so the default is true
     1814    if (!ippdbPrintMetadatas(stdout, output, "pstampUser", !simple)) {
     1815        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1816        psFree(output);
     1817        return false;
     1818    }
     1819
     1820    psFree(output);
     1821
     1822    return true;
     1823}
    17041824# endif
Note: See TracChangeset for help on using the changeset viewer.