use of com.serotonin.m2m2.i18n.Translations in project ma-modules-public by infiniteautomation.
the class ReportsDwr method getReportInstances.
/**
* Get report Instances and allow Admin users to get all report instances
* @param user
* @return
*/
private List<ReportInstance> getReportInstances(User user) {
// Allow Admin access to all report instances
List<ReportInstance> result;
if (Permissions.hasAdmin(user))
result = ReportDao.instance.getReportInstances();
else
result = ReportDao.instance.getReportInstances(user.getId());
Translations translations = getTranslations();
UserDao userDao = UserDao.instance;
for (ReportInstance i : result) {
i.setTranslations(translations);
User reportUser = userDao.getUser(i.getUserId());
if (reportUser != null)
i.setUsername(reportUser.getUsername());
else
i.setUsername(Common.translate("reports.validate.userDNE"));
}
return result;
}
use of com.serotonin.m2m2.i18n.Translations in project ma-modules-public by infiniteautomation.
the class ReportExportBase method execute.
protected void execute(HttpServletRequest request, HttpServletResponse response, int content) throws IOException {
// Get the report instance id
int instanceId = Integer.parseInt(request.getParameter("instanceId"));
// Get the report instance
ReportDao reportDao = ReportDao.instance;
ReportInstance instance = reportDao.getReportInstance(instanceId);
// Ensure the user is allowed access.
ReportCommon.ensureReportInstancePermission(Common.getUser(request), instance);
// Stream the content.
response.setContentType("text/csv");
Translations translations = Common.getTranslations();
if (content == CONTENT_REPORT) {
ExportCsvStreamer creator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
if (Common.databaseProxy.getNoSQLProxy() == null)
reportDao.reportInstanceDataSQL(instanceId, creator);
else
reportDao.reportInstanceDataNoSQL(instanceId, creator);
} else if (content == CONTENT_EVENTS)
new EventCsvStreamer(response.getWriter(), reportDao.getReportInstanceEvents(instanceId), translations);
else if (content == CONTENT_COMMENTS)
new UserCommentCsvStreamer(response.getWriter(), reportDao.getReportInstanceUserComments(instanceId), translations);
}
use of com.serotonin.m2m2.i18n.Translations in project ma-modules-public by infiniteautomation.
the class PointValueTimeCsvStreamCallback method row.
/* (non-Javadoc)
* @see com.serotonin.db.MappedRowCallback#row(java.lang.Object, int)
*/
@Override
public void row(PointValueTime pvt, int index) {
if (this.limiter.limited())
return;
try {
String annotation = null;
if (pvt.isAnnotated())
annotation = ((AnnotatedPointValueTime) pvt).getAnnotation(translations);
if (useRendered) {
// Convert to Alphanumeric Value
String textValue = Functions.getRenderedText(vo, pvt);
this.writePointValueTime(new AlphanumericValue(textValue), pvt.getTime(), annotation, vo);
} else if (unitConversion) {
if (pvt.getValue() instanceof NumericValue)
this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(pvt.getValue().getDoubleValue()), pvt.getTime(), annotation, vo);
else
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
} else {
if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
this.writePointValueTime(imageServletBuilder.buildAndExpand(pvt.getTime(), vo.getId()).toUri().toString(), pvt.getTime(), annotation, vo);
else
this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
}
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.serotonin.m2m2.i18n.Translations in project ma-modules-public by infiniteautomation.
the class DataImportController method importCsv.
/**
* The file needs to be in the format:
*
* Data Point XID, Device Name, Point name, Time, Value, Rendered, Annotation, Modify(Not used yet)
*
* @param reader
* @param model
* @return
* @throws IOException
* @throws TranslatableException
*/
private void importCsv(CSVReader csvReader, Map<String, Object> model, Translations translations, List<String> errorMessages) throws IOException, TranslatableException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
int rowErrors = 0;
int rowsImported = 0;
int rowsDeleted = 0;
// Basic validation of header
String[] nextLine = csvReader.readNext();
if (nextLine == null) {
errorMessages.add(new TranslatableMessage("dataImport.import.noData").translate(translations));
return;
}
if (nextLine.length != ExportCsvStreamer.columns) {
errorMessages.add(new TranslatableMessage("dataImport.import.invalidHeaders", nextLine.length, ExportCsvStreamer.columns).translate(translations));
return;
}
// Map of XIDs to non-running data points
Map<String, DataPointVO> voMap = new HashMap<String, DataPointVO>();
// Map of XIDs to running data points
Map<String, DataPointRT> rtMap = new HashMap<String, DataPointRT>();
// Read in all the rows
int row = 1;
String xid;
DataPointVO vo;
DataPointRT rt;
long time;
DataValue value;
PointValueTime pvt;
while ((nextLine = csvReader.readNext()) != null) {
if (nextLine.length != ExportCsvStreamer.columns) {
errorMessages.add(new TranslatableMessage("dataImport.import.invalidLength", row).translate(translations));
rowErrors++;
row++;
continue;
}
// Check XID
xid = nextLine[0];
if (StringUtils.isBlank(xid)) {
errorMessages.add(new TranslatableMessage("dataImport.import.badXid", xid, row).translate(translations));
rowErrors++;
row++;
continue;
}
// First Check to see if we already have a point
vo = voMap.get(xid);
rt = rtMap.get(xid);
// We will always have the vo in the map but the RT may be null if the point isn't running
if (vo == null) {
vo = dataPointDao.getDataPoint(xid);
if (vo == null) {
errorMessages.add(new TranslatableMessage("dataImport.import.xidNotFound", xid, row).translate(translations));
rowErrors++;
row++;
continue;
}
rt = Common.runtimeManager.getDataPoint(vo.getId());
rtMap.put(xid, rt);
voMap.put(xid, vo);
}
// Add or delete or nothing
String modify = nextLine[7];
if (StringUtils.equalsIgnoreCase("add", modify)) {
// Going to insert some data
time = ExportCsvStreamer.dtf.parseDateTime(nextLine[3]).getMillis();
value = DataValue.stringToValue(nextLine[4], vo.getPointLocator().getDataTypeId());
// Get Annotation
String annotation = nextLine[6];
if (annotation != null)
pvt = new AnnotatedPointValueTime(value, time, new TranslatableMessage("common.default", annotation));
else
pvt = new PointValueTime(value, time);
if (rt == null) {
// Insert Via DAO
pointValueDao.savePointValueAsync(vo.getId(), pvt, null);
} else {
// Insert Via RT
rt.savePointValueDirectToCache(pvt, null, true, true);
}
rowsImported++;
} else if (StringUtils.equalsIgnoreCase("delete", modify)) {
// Delete this entry
time = ExportCsvStreamer.dtf.parseDateTime(nextLine[3]).getMillis();
rowsDeleted += Common.runtimeManager.purgeDataPointValue(vo.getId(), time);
}
row++;
}
// Setup results
model.put("rowsImported", rowsImported);
model.put("rowsDeleted", rowsDeleted);
model.put("rowsWithErrors", rowErrors);
}
use of com.serotonin.m2m2.i18n.Translations in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvents.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvents() {
ProcessResult response = new ProcessResult();
final Translations translations = getTranslations();
List<MaintenanceEventVO> events = new MaintenanceEventDao().getMaintenanceEvents();
Collections.sort(events, new Comparator<MaintenanceEventVO>() {
@Override
public int compare(MaintenanceEventVO m1, MaintenanceEventVO m2) {
return m1.getDescription().translate(translations).compareTo(m1.getDescription().translate(translations));
}
});
response.addData(MODEL_ATTR_EVENTS, events);
List<IntStringPair> dataSources = new ArrayList<IntStringPair>();
for (DataSourceVO<?> ds : DataSourceDao.instance.getDataSources()) dataSources.add(new IntStringPair(ds.getId(), ds.getName()));
response.addData("dataSources", dataSources);
return response;
}
Aggregations