1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.assetapi;
18
19 import COM.FutureTense.Interfaces.ICS;
20 import COM.FutureTense.Util.ftErrors;
21 import com.fatwire.assetapi.common.AssetAccessException;
22 import com.fatwire.assetapi.data.AssetData;
23 import com.fatwire.assetapi.data.AssetDataManager;
24 import com.fatwire.assetapi.data.AssetId;
25 import com.fatwire.system.Session;
26 import com.fatwire.system.SessionFactory;
27 import tools.gsf.runtime.CSRuntimeException;
28
29 import java.util.Arrays;
30 import java.util.Collections;
31
32
33
34
35
36
37
38
39 public final class AssetDataUtils {
40 private AssetDataUtils() {
41 }
42
43
44
45
46
47
48
49
50 public static AssetData getAssetData(ICS ics, AssetId id) {
51 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
52 try {
53 for (AssetData data : mgr.read(Collections.singletonList(id))) {
54 return data;
55 }
56 } catch (AssetAccessException e) {
57 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
58 }
59 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
60 }
61
62
63
64
65
66
67
68
69
70 public static AssetData getAssetData(ICS ics, AssetId id, String... attributes) {
71 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
72 try {
73 return mgr.readAttributes(id, Arrays.asList(attributes));
74 } catch (AssetAccessException e) {
75 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
76 }
77 }
78
79
80
81
82
83
84
85
86
87 public static AssetData getCurrentAssetData(ICS ics, String... attributes) {
88 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
89 try {
90 AssetId id = AssetIdUtils.currentId(ics);
91 return mgr.readAttributes(id, Arrays.asList(attributes));
92 } catch (AssetAccessException e) {
93 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
94 }
95
96 }
97
98
99
100
101
102
103
104
105 public static AssetData getCurrentAssetData(ICS ics) {
106 AssetDataManager mgr = (AssetDataManager) getSession(ics).getManager(AssetDataManager.class.getName());
107 AssetId id = AssetIdUtils.currentId(ics);
108 try {
109 for (AssetData data : mgr.read(Collections.singletonList(id))) {
110 return data;
111 }
112 } catch (AssetAccessException e) {
113 throw new CSRuntimeException("Failed to read attribute data: " + e, ftErrors.exceptionerr, e);
114 }
115 throw new CSRuntimeException("Asset not found: " + id, ftErrors.badparams);
116
117 }
118
119 private static Session getSession(ICS ics) {
120 return SessionFactory.getSession(ics);
121 }
122
123 }