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;
}
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));
}
}
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);
}
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"));
}
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);
}
Aggregations