Search in sources :

Example 6 with Translations

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;
}
Also used : User(com.serotonin.m2m2.vo.User) UserDao(com.serotonin.m2m2.db.dao.UserDao) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance) Translations(com.serotonin.m2m2.i18n.Translations)

Example 7 with Translations

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);
}
Also used : UserCommentCsvStreamer(com.serotonin.m2m2.reports.web.UserCommentCsvStreamer) EventCsvStreamer(com.serotonin.m2m2.vo.export.EventCsvStreamer) ExportCsvStreamer(com.serotonin.m2m2.vo.export.ExportCsvStreamer) ReportDao(com.serotonin.m2m2.reports.ReportDao) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance) Translations(com.serotonin.m2m2.i18n.Translations)

Example 8 with 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);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 9 with Translations

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);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) HashMap(java.util.HashMap) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 10 with Translations

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;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Translations(com.serotonin.m2m2.i18n.Translations) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

Translations (com.serotonin.m2m2.i18n.Translations)17 HashMap (java.util.HashMap)14 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)8 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)7 User (com.serotonin.m2m2.vo.User)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)5 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Map (java.util.Map)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 InvalidArgumentException (com.serotonin.InvalidArgumentException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)3