1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.url.db;
17
18 import java.util.Collections;
19
20 import COM.FutureTense.Interfaces.ICS;
21
22 import com.fatwire.assetapi.data.AssetId;
23 import com.fatwire.cs.core.db.PreparedStmt;
24 import com.fatwire.cs.core.db.StatementParam;
25 import com.fatwire.gst.foundation.facade.logging.LogUtil;
26 import com.fatwire.gst.foundation.facade.sql.Row;
27 import com.fatwire.gst.foundation.facade.sql.SqlHelper;
28 import com.fatwire.gst.foundation.wra.SimpleWRADao;
29 import com.fatwire.gst.foundation.wra.SimpleWra;
30
31 import org.apache.commons.logging.Log;
32
33
34
35
36
37
38 public class DbSimpleWRADao implements SimpleWRADao {
39
40 private static final Log LOG = LogUtil.getLog(DbSimpleWRADao.class);
41
42 private final ICS ics;
43
44 public DbSimpleWRADao(final ICS ics) {
45 super();
46 this.ics = ics;
47 }
48
49 @Override
50 public SimpleWra getWra(final AssetId id) {
51
52 final PreparedStmt ASSET_SQL = new PreparedStmt("SELECT id, path, template, startdate, enddate FROM "
53 + id.getType() + " WHERE id=? AND status !='VO'", Collections.singletonList(id.getType()));
54
55 ASSET_SQL.setElement(0, id.getType(), "id");
56 final StatementParam param = ASSET_SQL.newParam();
57 param.setLong(0, id.getId());
58 final Row row = SqlHelper.selectSingle(ics, ASSET_SQL, param);
59 if (row == null) {
60 return null;
61 }
62 return new SimpleWra(row, id);
63
64 }
65
66 private static final String ASSETPUBLICATION_QRY = "SELECT p.name from Publication p, AssetPublication ap "
67 + "WHERE ap.assettype = ? " + "AND ap.assetid = ? " + "AND ap.pubid=p.id";
68 static final PreparedStmt AP_STMT = new PreparedStmt(ASSETPUBLICATION_QRY,
69 Collections.singletonList("AssetPublication"));
70
71
72
73
74
75 static {
76 AP_STMT.setElement(0, "AssetPublication", "assettype");
77 AP_STMT.setElement(1, "AssetPublication", "assetid");
78 }
79
80 @Override
81 public String resolveSite(final AssetId id) {
82 final StatementParam param = AP_STMT.newParam();
83 param.setString(0, id.getType());
84 param.setLong(1, id.getId());
85 String result = null;
86 for (final Row pubid : SqlHelper.select(ics, AP_STMT, param)) {
87 if (result != null) {
88 LOG.warn("Found asset "
89 + id
90 + " in more than one publication. It should not be shared; aliases are to be used for cross-site sharing. Controller will use first site found: "
91 + result);
92 } else {
93 result = pubid.getString("name");
94 }
95 }
96 return result;
97 }
98
99 }