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."); } }
/** * 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."); } }