Search in sources :

Example 86 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class DatabaseBackupWorkItem method restoreMysqlToDatabase.

public static TranslatableMessage restoreMysqlToDatabase(String mysqlPath, String host, String port, String user, String password, String database, String backupZipFile) {
    TranslatableMessage status = null;
    File sqlFile = new File(backupZipFile.replace(".zip", ".sql"));
    try {
        Process p = null;
        // only backup the data not included create database
        List<String> args = new ArrayList<String>();
        args.add(mysqlPath);
        args.add("-h" + host);
        args.add("-P" + port);
        args.add("-u" + user);
        args.add("-p" + password);
        args.add(database);
        // Unzip the File
        byte[] buffer = new byte[1024];
        try {
            // get the zip file content
            ZipInputStream zis = new ZipInputStream(new FileInputStream(backupZipFile));
            // get the zipped file list entry
            ZipEntry ze = zis.getNextEntry();
            if (ze != null) {
                FileOutputStream fos = new FileOutputStream(sqlFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
                ze = zis.getNextEntry();
            }
            zis.closeEntry();
            zis.close();
        } catch (IOException ex) {
            LOG.error(ex, ex.getCause());
            return new TranslatableMessage("systemSettings.databaseRestoreFailed", ex.getMessage());
        }
        ProcessBuilder pb = new ProcessBuilder(args);
        pb.redirectError(Redirect.INHERIT);
        pb.redirectInput(Redirect.from(sqlFile));
        p = pb.start();
        int processComplete = p.waitFor();
        if (processComplete == 0) {
            status = new TranslatableMessage("systemSettings.databaseRestored");
            LOG.info("Backup restored successfully for" + database + " in " + host + ":" + port);
        } else {
            status = new TranslatableMessage("systemSettings.databaseRestoreFailed", processComplete);
            LOG.info("Could not restore the backup for " + database + " in " + host + ":" + port);
        }
    } catch (IOException ioe) {
        LOG.error(ioe, ioe.getCause());
        status = new TranslatableMessage("systemSettings.databaseRestoreFailed", ioe.getMessage());
    } catch (Exception e) {
        LOG.error(e, e.getCause());
        new TranslatableMessage("systemSettings.databaseRestoreFailed", e.getMessage());
    } finally {
        if (sqlFile.exists())
            sqlFile.delete();
    }
    return status;
}
Also used : ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ParseException(java.text.ParseException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) FileOutputStream(java.io.FileOutputStream) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) File(java.io.File)

Example 87 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class PublisherRT method checkForDisabledPoints.

private synchronized void checkForDisabledPoints() {
    int badPointId = -1;
    String disabledPoint = null;
    for (PublishedPointRT<T> rt : pointRTs) {
        if (!rt.isPointEnabled()) {
            badPointId = rt.getVo().getDataPointId();
            disabledPoint = DataPointDao.instance.getXidById(badPointId);
            break;
        }
    }
    boolean foundBadPoint = badPointId != -1;
    if (pointEventActive != foundBadPoint) {
        pointEventActive = foundBadPoint;
        if (pointEventActive) {
            // A published point has been terminated, was never enabled, or no longer exists.
            TranslatableMessage lm;
            if (disabledPoint == null)
                // The point is missing
                lm = new TranslatableMessage("event.publish.pointMissing", badPointId);
            else
                lm = new TranslatableMessage("event.publish.pointDisabled", disabledPoint);
            Common.eventManager.raiseEvent(pointDisabledEventType, Common.timer.currentTimeMillis(), true, vo.getAlarmLevel(POINT_DISABLED_EVENT, AlarmLevels.URGENT), lm, createEventContext());
        } else
            // Everything is good
            Common.eventManager.returnToNormal(pointDisabledEventType, Common.timer.currentTimeMillis(), vo.getAlarmLevel(POINT_DISABLED_EVENT, AlarmLevels.URGENT));
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 88 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class DateUtils method getDuration.

public static TranslatableMessage getDuration(long duration) {
    if (duration < 1000)
        return new TranslatableMessage("common.duration.millis", duration);
    if (duration < 10000) {
        String s = "" + (duration / 1000) + '.';
        s += (int) (((double) (duration % 1000)) / 10 + 0.5);
        return new TranslatableMessage("common.duration.seconds", s);
    }
    if (duration < 60000) {
        String s = "" + (duration / 1000) + '.';
        s += (int) (((double) (duration % 1000)) / 100 + 0.5);
        return new TranslatableMessage("common.duration.seconds", s);
    }
    // Convert to seconds
    duration /= 1000;
    if (duration < 600)
        return new TranslatableMessage("common.duration.minSec", duration / 60, duration % 60);
    // Convert to minutes
    duration /= 60;
    if (duration < 60)
        return new TranslatableMessage("common.duration.minutes", duration);
    if (duration < 1440)
        return new TranslatableMessage("common.duration.hourMin", duration / 60, duration % 60);
    // Convert to hours
    duration /= 60;
    return new TranslatableMessage("common.duration.hours", duration);
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 89 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class DateUtils method getDurationCourse.

public static TranslatableMessage getDurationCourse(long duration) {
    if (duration < 60000)
        return new TranslatableMessage("common.tp.ltDescription", 1, new TranslatableMessage("common.tp.minute"));
    // Convert to minutes
    duration /= 60000;
    if (duration < 60)
        return new TranslatableMessage("common.tp.description", duration, new TranslatableMessage("common.tp.minutes"));
    // Convert to hours
    duration /= 60;
    if (duration < 24)
        return new TranslatableMessage("common.tp.gtDescription", duration, new TranslatableMessage("common.tp.hours"));
    // Convert to days
    duration /= 24;
    return new TranslatableMessage("common.tp.gtDescription", duration, new TranslatableMessage("common.tp.days"));
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 90 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class ScriptPointValueSetter method set.

// Ensure points are settable and the setter has permissions
public void set(IDataPointValueSource point, Object value, long timestamp, String annotation) {
    DataPointRT dprt = (DataPointRT) point;
    if (!dprt.getVO().getPointLocator().isSettable())
        return;
    if (permissions != null && !Permissions.hasPermission(dprt.getVO().getSetPermission(), permissions.getDataPointSetPermissions()))
        throw new ScriptPermissionsException(new TranslatableMessage("script.set.permissionDenied", dprt.getVO().getXid()));
    setImpl(point, value, timestamp, annotation);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)180 User (com.serotonin.m2m2.vo.User)53 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)33 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)33 IOException (java.io.IOException)28 HashMap (java.util.HashMap)27 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)24 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)22 ArrayList (java.util.ArrayList)22 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)20 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)20 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)19 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)17 File (java.io.File)16 URI (java.net.URI)16 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 ResponseEntity (org.springframework.http.ResponseEntity)11