use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class RhinoScriptTestData method getPointValuesBetween.
/**
* @param dataTypeId
* @param from
* @param to
*/
public static List<PointValueTime> getPointValuesBetween(int dataTypeId, int id, long from, long to) {
switch(dataTypeId) {
case DataTypes.ALPHANUMERIC:
case DataTypes.BINARY:
case DataTypes.IMAGE:
case DataTypes.MULTISTATE:
default:
throw new ShouldNeverHappenException("Unimplemented");
case DataTypes.NUMERIC:
List<PointValueTime> values = new ArrayList<PointValueTime>();
List<PointValueTime> pvts = numericPvts.get(id);
for (PointValueTime pvt : pvts) {
if ((pvt.getTime() > from) || (pvt.getTime() <= to))
values.add(pvt);
}
return values;
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class MangoTestBase method after.
@After
public void after() {
SimulationTimerProvider provider = (SimulationTimerProvider) Providers.get(TimerProvider.class);
provider.reset();
Common.runtimeManager.terminate();
Common.runtimeManager.joinTermination();
H2InMemoryDatabaseProxy proxy = (H2InMemoryDatabaseProxy) Common.databaseProxy;
try {
proxy.clean();
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class ModulesController method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
// Check for a license download token.
String token = request.getParameter("token");
if (!StringUtils.isEmpty(token)) {
if (downloadLicense(token))
model.put("licenseDownloaded", true);
}
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
Module core = ModuleRegistry.getCoreModule();
modules.add(0, core);
model.put("guid", Providers.get(ICoreLicense.class).getGuid());
model.put("distributor", Common.envProps.getString("distributor"));
model.put("modules", modules);
// Add in the Unloaded modules
model.put("unloadedModules", ModuleRegistry.getUnloadedModules());
// The JSON
Map<String, Object> json = new HashMap<>();
json.put("guid", Providers.get(ICoreLicense.class).getGuid());
json.put("description", SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
json.put("distributor", Common.envProps.getString("distributor"));
Map<String, String> jsonModules = new HashMap<>();
json.put("modules", jsonModules);
for (Module module : modules) {
jsonModules.put(module.getName(), module.getVersion().toString());
}
try {
StringWriter out = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(Common.JSON_CONTEXT, out);
jsonWriter.writeObject(json);
model.put("json", out.toString());
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
return null;
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class FileUploadController method prepareResponse.
/**
* @param request
* @param response
* @param model
* @throws IOException
* @throws JsonException
* @throws FileUploadException
*/
private FileUploadView prepareResponse(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws IOException, JsonException, FileUploadException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
String dataType = multipartRequest.getParameter("dataType");
String uploadType = multipartRequest.getParameter("uploadType");
List<Object> fileInfo = new ArrayList<Object>();
Translations translations = ControllerUtils.getTranslations(request);
Iterator<String> itr = multipartRequest.getFileNames();
while (itr.hasNext()) {
MultipartFile file = multipartRequest.getFile(itr.next());
if (!file.isEmpty()) {
Map<String, Object> info = new HashMap<String, Object>();
info.put("filename", file.getOriginalFilename());
info.put("dataType", dataType);
parseFile(file.getInputStream(), info, translations, request);
fileInfo.add(info);
}
}
model.put("fileInfo", fileInfo);
boolean iframe = false;
boolean html5 = false;
boolean flash = false;
if (uploadType.equals("iframe")) {
iframe = true;
response.setContentType("text/html");
} else if (uploadType.equals("html5")) {
html5 = true;
response.setContentType("application/json");
} else if (uploadType.equals("flash")) {
flash = true;
response.setContentType("text/plain");
}
if (iframe || html5) {
return new FileUploadView(iframe);
} else if (flash) {
// TODO handle Flash
throw new ShouldNeverHappenException("Flash upload not supported.");
} else {
throw new ShouldNeverHappenException("Invalid file upload type.");
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class RecipientListEntryBean method createEmailRecipient.
public EmailRecipient createEmailRecipient() {
switch(recipientType) {
case EmailRecipient.TYPE_MAILING_LIST:
MailingList ml = new MailingList();
ml.setId(referenceId);
return ml;
case EmailRecipient.TYPE_USER:
UserEntry u = new UserEntry();
u.setUserId(referenceId);
return u;
case EmailRecipient.TYPE_ADDRESS:
AddressEntry a = new AddressEntry();
a.setAddress(referenceAddress);
return a;
}
throw new ShouldNeverHappenException("Unknown email recipient type: " + recipientType);
}
Aggregations