1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.assetapi;
18
19 import java.util.Arrays;
20 import java.util.Collections;
21
22 import COM.FutureTense.Interfaces.ICS;
23 import COM.FutureTense.Util.ftErrors;
24
25 import com.fatwire.assetapi.common.AssetAccessException;
26 import com.fatwire.assetapi.data.AssetData;
27 import com.fatwire.assetapi.data.AssetDataManager;
28 import com.fatwire.assetapi.data.AssetId;
29 import com.fatwire.gst.foundation.CSRuntimeException;
30 import com.fatwire.gst.foundation.facade.ics.ICSFactory;
31 import com.fatwire.system.Session;
32 import com.fatwire.system.SessionFactory;
33
34
35
36
37
38
39
40
41 public final class AssetDataUtils {
42 private AssetDataUtils() {
43 }
44
45
46
47
48
49
50
51
52
53
54 @Deprecated
55 public static AssetData getAssetData(String c, String cid, String... attributes) {
56 return getAssetData(AssetIdUtils.createAssetId(c, cid), attributes);
57 }
58
59
60
61
62
63
64
65
66 @Deprecated
67 public static AssetData getAssetData(AssetId id) {
68 return getAssetData(ICSFactory.getOrCreateICS(), id);
69 }
70
71
72
73
74
75
76
77
78 public static AssetData getAssetData(ICS ics, AssetId id) {
79 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
80 try {
81 for (AssetData data : mgr.read(Collections.singletonList(id))) {
82 return data;
83 }
84 } catch (AssetAccessException e) {
85 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
86 }
87 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
88 }
89
90
91
92
93
94
95
96
97
98 @Deprecated
99 public static AssetData getAssetData(AssetId id, String... attributes) {
100 return getAssetData(ICSFactory.getOrCreateICS(), id, attributes);
101 }
102
103
104
105
106
107
108
109
110 public static AssetData getAssetData(ICS ics, AssetId id, String... attributes) {
111 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
112 try {
113 return mgr.readAttributes(id, Arrays.asList(attributes));
114 } catch (AssetAccessException e) {
115 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
116 }
117 }
118
119
120
121
122
123
124
125
126
127 public static AssetData getCurrentAssetData(ICS ics, String... attributes) {
128 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
129 try {
130 AssetId id = AssetIdUtils.currentId(ics);
131 return mgr.readAttributes(id, Arrays.asList(attributes));
132 } catch (AssetAccessException e) {
133 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
134 }
135
136 }
137
138
139
140
141
142
143
144
145 public static AssetData getCurrentAssetData(ICS ics) {
146 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
147 AssetId id = AssetIdUtils.currentId(ics);
148 try {
149 for (AssetData data : mgr.read(Collections.singletonList(id))) {
150 return data;
151 }
152 } catch (AssetAccessException e) {
153 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
154 }
155 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
156
157 }
158
159 private static Session getSession(ICS ics) {
160 return SessionFactory.getSession(ics);
161 }
162
163 }