コード例 #1
0
 public static IList listSingleAsset(ICS ics, String c, String cid) {
   ics.RegisterList("spu-gtfa", null);
   AssetList al = new AssetList();
   al.setField("id", cid);
   al.setType(c);
   al.setExcludeVoided(true);
   al.setList("spu-gtfa");
   al.execute(ics);
   IList spugtfa = ics.GetList("spu-gtfa");
   ics.RegisterList("spu-gtfa", null);
   if (spugtfa != null && spugtfa.hasData()) {
     if (spugtfa.numRows() > 1) {
       throw new IllegalStateException(
           "ASSET.LIST failed for "
               + c
               + ":"
               + cid
               + ": multiple matches found:"
               + spugtfa.numRows());
     }
     return new IterableIListWrapper(spugtfa).iterator().next();
   } else {
     throw new IllegalStateException(
         "ASSET.LIST failed for " + c + ":" + cid + ": no data found.");
   }
 }
コード例 #2
0
 /**
  * Get a single field from a specified asset. Only one result must be returned from this search or
  * an exception will be thrown. Pubid is optional.
  *
  * @param ics Content Server context object
  * @param c current asset
  * @param cid content id
  * @param field field to get
  * @return single field value
  */
 public static String getRequiredSingleField(ICS ics, String c, String cid, String field) {
   ics.RegisterList("spu-gtfa", null);
   AssetList al = new AssetList();
   al.setField("id", cid);
   al.setType(c);
   al.setExcludeVoided(true);
   al.setList("spu-gtfa");
   al.execute(ics);
   IList spugtfa = ics.GetList("spu-gtfa");
   ics.RegisterList("spu-gtfa", null);
   if (spugtfa != null && spugtfa.hasData()) {
     if (spugtfa.numRows() > 1) {
       throw new IllegalStateException(
           "ASSET.LIST failed for "
               + c
               + ":"
               + cid
               + ": multiple matches found:"
               + spugtfa.numRows());
     }
     spugtfa.moveTo(1);
     String ret = IListUtils.getStringValue(spugtfa, field);
     if (ret == null || ret.length() == 0) {
       throw new IllegalStateException("No " + field + " found for asset " + c + ":" + cid);
     }
     return ret;
   } else {
     throw new IllegalStateException(
         "ASSET.LIST failed for " + c + ":" + cid + ": no data found.");
   }
 }
コード例 #3
0
  /**
   * Look up asset id by name
   *
   * @param ics context
   * @param c type
   * @param name name field value
   * @return asset id or null if not found.
   */
  public static AssetId lookupAssetId(ICS ics, String c, String name) {
    if (c == null || c.length() == 0) {
      throw new IllegalArgumentException("No such asset type: " + c);
    }

    if (!SqlHelper.tableExists(ics, c)) {
      throw new IllegalArgumentException("No such asset type: " + c);
    }

    if (name == null || name.length() == 0) {
      throw new IllegalArgumentException(
          "Cannot look up asset by name with an actual name.  Type: " + c);
    }
    ics.RegisterList("spu-gtfa", null);
    AssetList al = new AssetList();
    al.setField("name", name);
    al.setType(c);
    al.setExcludeVoided(false);
    al.setList("spu-gtfa");
    al.execute(ics);
    IList spugtfa = ics.GetList("spu-gtfa");
    ics.RegisterList("spu-gtfa", null);
    if (spugtfa != null && spugtfa.hasData()) {
      for (Row listRow : new IListIterable(spugtfa)) {
        return AssetIdUtils.createAssetId(c, listRow.getString("id"));
      }
    }
    return null;
  }
  private Map<String, String> getCSElementAttributes(ICS ics, String resourceName) {
    final StatementParam param = stmt.newParam();
    param.setString(0, resourceName);

    Map<String, String> rowMap = new HashMap<String, String>();
    IList i = ics.SQL(stmt, param, true);
    if (ics.GetErrno() != -101) {
      i.moveTo(0);
      try {
        rowMap.put("url", i.getValue("url"));
        rowMap.put("resdetails1", i.getValue("resdetails1"));
        rowMap.put("resdetails2", i.getValue("resdetails2"));
      } catch (NoSuchFieldException e) {
        throw new RuntimeException(
            "NoSuchFieldException returned "
                + ics.GetErrno()
                + " and errstr: "
                + " for "
                + stmt.toString());
      }
      ics.ClearErrno();
    } else if (ics.GetErrno() != 0) {
      throw new RuntimeException(
          "ics.SQL returned " + ics.GetErrno() + " and errstr: " + " for " + stmt.toString());
    }
    return rowMap;
  }
コード例 #5
0
 /**
  * Reads an IList with collumns <tt>assettype</tt> and <tt>assetid</tt> and creates a Collection
  * of AssetId objects.
  *
  * @param result
  * @return Collection of AssetIds, never null.
  */
 public static Collection<AssetId> toAssetIdCollection(IList result) {
   if (result == null || !result.hasData()) return Collections.emptyList();
   final List<AssetId> list = new LinkedList<AssetId>();
   for (IList row : new IterableIListWrapper(result)) {
     AssetId id;
     try {
       id = AssetIdUtils.createAssetId(row.getValue("assettype"), row.getValue("assetid"));
       list.add(id);
     } catch (NoSuchFieldException e) {
       throw new RuntimeException(e.getMessage());
     }
   }
   return list;
 }
コード例 #6
0
 /**
  * Return a string value for a column. Wraps the possible checked exception NoSuchFieldException
  * with an IllegalArgumentException
  *
  * @param list IList to interrogate
  * @param colname name of column to return
  * @return string value
  * @throws IllegalArgumentException if the column name is not found
  */
 public static String getStringValue(IList list, String colname) {
   try {
     return list.getValue(colname);
   } catch (NoSuchFieldException e) {
     throw new IllegalArgumentException("No such field: " + colname, e);
   }
 }
コード例 #7
0
 /**
  * Return a long value for a column. Wraps the possible checked exception NoSuchFieldException
  * with an IllegalArgumentException
  *
  * @param list IList to interrogate
  * @param colname name of column to return
  * @return long value
  * @throws IllegalArgumentException if the column name is not found
  * @throws NumberFormatException if the column being queried does not contain a long.
  */
 public static long getLongValue(IList list, String colname) {
   try {
     String s = list.getValue(colname);
     return Long.valueOf(s);
   } catch (NoSuchFieldException e) {
     throw new IllegalArgumentException("No such field: " + colname, e);
   }
 }
コード例 #8
0
 /**
  * Return true if the asset exists in the database, and false if it does not.
  *
  * @param ics context
  * @param c asset type
  * @param cid asset id
  * @return true if the asset exists, false if it does not
  */
 public static boolean assetExists(ICS ics, String c, String cid) {
   if (c == null || c.length() == 0) {
     return false;
   }
   if (cid == null || cid.length() == 0) {
     return false;
   }
   ics.RegisterList("spu-gtfa", null);
   AssetList al = new AssetList();
   al.setField("id", cid);
   al.setType(c);
   al.setExcludeVoided(false);
   al.setList("spu-gtfa");
   al.execute(ics);
   IList spugtfa = ics.GetList("spu-gtfa");
   ics.RegisterList("spu-gtfa", null);
   return spugtfa != null && spugtfa.hasData();
 }
コード例 #9
0
  public static boolean assetExistsByName(ICS ics, String c, String name) {
    if (c == null || c.length() == 0) {
      return false;
    }

    if (!SqlHelper.tableExists(ics, c)) {
      return false;
    }

    if (name == null || name.length() == 0) {
      return false;
    }
    ics.RegisterList("spu-gtfa", null);
    AssetList al = new AssetList();
    al.setField("name", name);
    al.setType(c);
    al.setExcludeVoided(false);
    al.setList("spu-gtfa");
    al.execute(ics);
    IList spugtfa = ics.GetList("spu-gtfa");
    ics.RegisterList("spu-gtfa", null);
    return spugtfa != null && spugtfa.hasData();
  }