This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
ResourceGroupsDataSource.java
174 lines (144 loc) · 7.3 KB
/
ResourceGroupsDataSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* RHQ Management Platform
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.coregui.client.inventory.groups;
import static org.rhq.coregui.client.inventory.groups.ResourceGroupDataSourceField.CATEGORY;
import static org.rhq.coregui.client.inventory.groups.ResourceGroupDataSourceField.DESCRIPTION;
import static org.rhq.coregui.client.inventory.groups.ResourceGroupDataSourceField.NAME;
import static org.rhq.coregui.client.inventory.groups.ResourceGroupDataSourceField.PLUGIN;
import static org.rhq.coregui.client.inventory.groups.ResourceGroupDataSourceField.TYPE;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.rpc.RPCResponse;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import org.rhq.core.domain.criteria.ResourceGroupCriteria;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.resource.group.GroupCategory;
import org.rhq.core.domain.resource.group.ResourceGroup;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.domain.util.ResourceTypeUtility;
import org.rhq.coregui.client.CoreGUI;
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.gwt.ResourceGroupGWTServiceAsync;
import org.rhq.coregui.client.util.RPCDataSource;
/**
* @author Greg Hinkle
*/
public class ResourceGroupsDataSource extends RPCDataSource<ResourceGroup, ResourceGroupCriteria> {
public static final String FILTER_GROUP_IDS = "resourceGroupIds";
private ResourceGroupGWTServiceAsync groupService = GWTServiceLookup.getResourceGroupService();
private static ResourceGroupsDataSource INSTANCE;
public static ResourceGroupsDataSource getInstance() {
if (INSTANCE == null) {
INSTANCE = new ResourceGroupsDataSource();
}
return INSTANCE;
}
public ResourceGroupsDataSource() {
super();
List<DataSourceField> fields = addDataSourceFields();
addFields(fields);
}
@Override
protected List<DataSourceField> addDataSourceFields() {
List<DataSourceField> fields = super.addDataSourceFields();
DataSourceField idDataField = new DataSourceIntegerField("id", MSG.common_title_id(), 20);
idDataField.setPrimaryKey(true);
fields.add(idDataField);
DataSourceTextField nameDataField = new DataSourceTextField(NAME.propertyName(), NAME.title(), 200);
fields.add(nameDataField);
DataSourceTextField descriptionDataField = new DataSourceTextField(DESCRIPTION.propertyName(),
DESCRIPTION.title());
fields.add(descriptionDataField);
DataSourceTextField typeNameDataField = new DataSourceTextField(TYPE.propertyName(), TYPE.title());
fields.add(typeNameDataField);
DataSourceTextField pluginNameDataField = new DataSourceTextField(PLUGIN.propertyName(), PLUGIN.title());
fields.add(pluginNameDataField);
DataSourceTextField categoryDataField = new DataSourceTextField(CATEGORY.propertyName(), CATEGORY.title());
fields.add(categoryDataField);
return fields;
}
@Override
public void executeFetch(final DSRequest request, final DSResponse response, final ResourceGroupCriteria criteria) {
groupService.findResourceGroupsByCriteria(criteria, new AsyncCallback<PageList<ResourceGroup>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.dataSource_resourceGroups_loadFailed(), caught);
response.setStatus(RPCResponse.STATUS_FAILURE);
processResponse(request.getRequestId(), response);
}
public void onSuccess(PageList<ResourceGroup> result) {
response.setData(buildRecords(result));
setPagingInfo(response, result);
processResponse(request.getRequestId(), response);
}
});
}
@Override
protected ResourceGroupCriteria getFetchCriteria(final DSRequest request) {
ResourceGroupCriteria criteria = new ResourceGroupCriteria();
criteria.addFilterId(getFilter(request, "id", Integer.class));
criteria.addFilterName(getFilter(request, NAME.propertyName(), String.class));
criteria.addFilterGroupCategory(getFilter(request, CATEGORY.propertyName(), GroupCategory.class));
criteria.addFilterDownMemberCount(getFilter(request, "downMemberCount", Long.class));
criteria.addFilterExplicitResourceIds(getFilter(request, "explicitResourceId", Integer.class));
criteria.addFilterGroupDefinitionId(getFilter(request, "groupDefinitionId", Integer.class));
criteria.setSearchExpression(getFilter(request, "search", String.class));
criteria.addFilterIds(getArrayFilter(request, FILTER_GROUP_IDS, Integer.class));
return criteria;
}
@Override
public ResourceGroup copyValues(Record from) {
Integer idAttrib = from.getAttributeAsInt("id");
String nameAttrib = from.getAttribute(NAME.propertyName());
String descriptionAttrib = from.getAttribute(DESCRIPTION.propertyName());
String typeNameAttrib = from.getAttribute(TYPE.propertyName());
String pluginNameAttrib = from.getAttribute(PLUGIN.propertyName());
ResourceType rt = null;
ResourceGroup rg = new ResourceGroup(nameAttrib);
rg.setId(idAttrib);
rg.setDescription(descriptionAttrib);
if (null != typeNameAttrib) {
rt = new ResourceType();
rt.setName(typeNameAttrib);
rt.setPlugin(pluginNameAttrib);
rg.setResourceType(rt);
}
return rg;
}
@Override
public ListGridRecord copyValues(ResourceGroup from) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("group", from);
record.setAttribute("id", from.getId());
record.setAttribute(NAME.propertyName(), from.getName());
record.setAttribute(DESCRIPTION.propertyName(), from.getDescription());
record.setAttribute(CATEGORY.propertyName(), from.getGroupCategory().name());
if (from.getResourceType() != null) {
record.setAttribute("resourceType", from.getResourceType());
record.setAttribute(TYPE.propertyName(), ResourceTypeUtility.displayName(from.getResourceType()));
record.setAttribute(PLUGIN.propertyName(), from.getResourceType().getPlugin());
}
return record;
}
}