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 public static AssetData getAssetData(String c, String cid, String... attributes) {
55 return getAssetData(AssetIdUtils.createAssetId(c, cid), attributes);
56 }
57
58
59
60
61
62
63
64 public static AssetData getAssetData(AssetId id) {
65 return getAssetData(ICSFactory.getOrCreateICS(), id);
66 }
67
68
69
70
71
72
73
74
75 public static AssetData getAssetData(ICS ics, AssetId id) {
76 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
77 try {
78 for (AssetData data : mgr.read(Collections.singletonList(id))) {
79 return data;
80 }
81 } catch (AssetAccessException e) {
82 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
83 }
84 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
85 }
86
87
88
89
90
91
92
93
94 public static AssetData getAssetData(AssetId id, String... attributes) {
95 return getAssetData(ICSFactory.getOrCreateICS(), id, attributes);
96 }
97
98
99
100
101
102
103
104
105 public static AssetData getAssetData(ICS ics, AssetId id, String... attributes) {
106 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
107 try {
108 return mgr.readAttributes(id, Arrays.asList(attributes));
109 } catch (AssetAccessException e) {
110 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
111 }
112 }
113
114
115
116
117
118
119
120
121
122 public static AssetData getCurrentAssetData(ICS ics, String... attributes) {
123 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
124 try {
125 AssetId id = AssetIdUtils.currentId(ics);
126 return mgr.readAttributes(id, Arrays.asList(attributes));
127 } catch (AssetAccessException e) {
128 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
129 }
130
131 }
132
133
134
135
136
137
138
139
140 public static AssetData getCurrentAssetData(ICS ics) {
141 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
142 AssetId id = AssetIdUtils.currentId(ics);
143 try {
144 for (AssetData data : mgr.read(Collections.singletonList(id))) {
145 return data;
146 }
147 } catch (AssetAccessException e) {
148 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
149 }
150 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
151
152 }
153
154 private static Session getSession(ICS ics) {
155 return SessionFactory.getSession(ics);
156 }
157
158 }