Search in sources :

Example 66 with ShouldNeverHappenException

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;
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Example 67 with ShouldNeverHappenException

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);
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TimerProvider(com.serotonin.provider.TimerProvider) URISyntaxException(java.net.URISyntaxException) JsonException(com.serotonin.json.JsonException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) After(org.junit.After)

Example 68 with ShouldNeverHappenException

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;
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) Module(com.serotonin.m2m2.module.Module) JsonWriter(com.serotonin.json.JsonWriter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 69 with ShouldNeverHappenException

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.");
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MultipartFile(org.springframework.web.multipart.MultipartFile) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) Translations(com.serotonin.m2m2.i18n.Translations) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 70 with ShouldNeverHappenException

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);
}
Also used : AddressEntry(com.serotonin.m2m2.vo.mailingList.AddressEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) UserEntry(com.serotonin.m2m2.vo.mailingList.UserEntry)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4