use of com.serotonin.db.pair.StringStringPair in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method editInit.
//
//
// View editing
//
@DwrPermission(user = true)
public Map<String, Object> editInit() {
Map<String, Object> result = new HashMap<String, Object>();
User user = Common.getUser();
// Users with which to share.
// result.put("shareUsers", getShareUsers(user));
// Users already sharing with.
// Legacy code, can remove result.put("viewUsers", GraphicalViewsCommon.getUserEditView(user).getViewUsers());
// View component types
List<StringStringPair> components = new ArrayList<StringStringPair>();
for (ImplDefinition impl : ViewComponent.getImplementations()) components.add(new StringStringPair(impl.getName(), translate(impl.getNameKey())));
result.put("componentTypes", components);
// Available points
List<DataPointVO> allPoints = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
List<DataPointBean> availablePoints = new ArrayList<DataPointBean>();
final boolean admin = Permissions.hasAdmin(user);
for (DataPointVO dataPoint : allPoints) {
if (admin || Permissions.hasDataPointReadPermission(user, dataPoint))
availablePoints.add(new DataPointBean(dataPoint));
}
result.put("pointList", availablePoints);
return result;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class DataPointDwr method getEventDetectorOptions.
/**
* Get a list of available Point Event Detectors for this point
*
* @param vo
* @return
*/
@DwrPermission(user = true)
public ProcessResult getEventDetectorOptions(int dataTypeId) {
ProcessResult response = new ProcessResult();
List<EventDetectorDefinition<?>> definitions = ModuleRegistry.getEventDetectorDefinitions();
List<StringStringPair> list = new ArrayList<StringStringPair>();
for (EventDetectorDefinition<?> definition : definitions) {
AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
if (vo instanceof AbstractPointEventDetectorVO) {
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) vo;
if (ped.supports(dataTypeId)) {
list.add(new StringStringPair(definition.getDescriptionKey(), definition.getEventDetectorTypeName()));
}
}
}
response.addData("options", list);
return response;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method init.
@DwrPermission(user = true)
public ProcessResult init() {
ProcessResult response = new ProcessResult();
User user = Common.getUser();
List<DataSourceVO<?>> allDataSources = Common.runtimeManager.getDataSources();
if (Permissions.hasAdmin(user)) {
response.addData("dataSources", allDataSources);
List<StringStringPair> translatedTypes = new ArrayList<>();
for (String type : ModuleRegistry.getDataSourceDefinitionTypes()) translatedTypes.add(new StringStringPair(type, translate(ModuleRegistry.getDataSourceDefinition(type).getDescriptionKey())));
StringStringPairComparator.sort(translatedTypes);
response.addData("types", translatedTypes);
} else {
List<DataSourceVO<?>> dataSources = new ArrayList<>();
for (DataSourceVO<?> ds : allDataSources) {
if (Permissions.hasDataSourcePermission(user, ds))
dataSources.add(ds);
}
response.addData("dataSources", dataSources);
}
return response;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class ModulesDwr method startDownloads.
@DwrPermission(admin = true)
public static String startDownloads(List<StringStringPair> modules, boolean backup, boolean restart) {
synchronized (UPGRADE_DOWNLOADER_LOCK) {
if (UPGRADE_DOWNLOADER != null)
return Common.translate("modules.versionCheck.occupied");
}
// Check if the selected modules will result in a version-consistent system.
try {
// Create the request
Map<String, Object> json = new HashMap<>();
Map<String, String> jsonModules = new HashMap<>();
json.put("modules", jsonModules);
Version coreVersion = Common.getVersion();
jsonModules.put("core", coreVersion.toString());
for (StringStringPair module : modules) jsonModules.put(module.getKey(), module.getValue());
StringWriter stringWriter = new StringWriter();
new JsonWriter(Common.JSON_CONTEXT, stringWriter).writeObject(json);
String requestData = stringWriter.toString();
// Send the request
String baseUrl = Common.envProps.getString("store.url");
baseUrl += "/servlet/consistencyCheck";
HttpPost post = new HttpPost(baseUrl);
post.setEntity(new StringEntity(requestData));
String responseData = HttpUtils4.getTextContent(Common.getHttpClient(), post, 1);
// Parse the response
JsonTypeReader jsonReader = new JsonTypeReader(responseData);
String result = jsonReader.read().toString();
if (!"ok".equals(result))
return result;
} catch (Exception e) {
LOG.error("", e);
return e.getMessage();
}
synchronized (UPGRADE_DOWNLOADER_LOCK) {
// Ensure that 2 downloads cannot start at the same time.
if (UPGRADE_DOWNLOADER == null) {
UPGRADE_DOWNLOADER = new UpgradeDownloader(modules, backup, restart, Common.getHttpUser());
// Clear out common info
resetUpgradeStatus();
Common.backgroundProcessing.execute(UPGRADE_DOWNLOADER);
} else
return Common.translate("modules.versionCheck.occupied");
}
return null;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class TimeZoneUtils method getTimeZoneIdsWithOffset.
public static List<StringStringPair> getTimeZoneIdsWithOffset() {
List<TzSort> tzs = new ArrayList<TimeZoneUtils.TzSort>();
String[] ids = TimeZone.getAvailableIDs();
for (String id : ids) {
if (id.matches(REGEX)) {
TzSort t = new TzSort();
t.offset = TimeZone.getTimeZone(id).getRawOffset();
t.info = new StringStringPair(id, formatOffset(t.offset) + " " + id);
tzs.add(t);
}
}
Collections.sort(tzs);
List<StringStringPair> result = new ArrayList<StringStringPair>();
for (TzSort t : tzs) result.add(t.info);
return result;
}
Aggregations