Search in sources :

Example 76 with ProcessResult

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

the class DataPointDwr method getUnitsList.

@DwrPermission(user = true)
public ProcessResult getUnitsList() {
    ProcessResult result = new ProcessResult();
    List<DojoMemoryStoreListItem> pairs = new ArrayList<>();
    // Get SI Units
    int id = 0;
    for (Unit<?> unit : SI.getInstance().getUnits()) {
        pairs.add(new DojoMemoryStoreListItem(unit.toString(), id++));
    }
    // Get US Units
    for (Unit<?> unit : NonSI.getInstance().getUnits()) {
        pairs.add(new DojoMemoryStoreListItem(unit.toString(), id++));
    }
    List<String> addedUnits = UnitUtil.getAddedUnitLabels();
    for (String unit : addedUnits) {
        pairs.add(new DojoMemoryStoreListItem(unit, id++));
    }
    Collections.sort(pairs, new Comparator<DojoMemoryStoreListItem>() {

        @Override
        public int compare(DojoMemoryStoreListItem arg0, DojoMemoryStoreListItem arg1) {
            return arg0.getName().compareToIgnoreCase(arg1.getName());
        }
    });
    result.addData("units", pairs);
    return result;
}
Also used : DojoMemoryStoreListItem(com.serotonin.m2m2.web.dojo.DojoMemoryStoreListItem) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 77 with ProcessResult

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

the class DataPointEditDwr method ensureEditingPointMatch.

@DwrPermission(user = true)
public ProcessResult ensureEditingPointMatch(int uiPointId) {
    ProcessResult result = new ProcessResult();
    User user = Common.getHttpUser();
    DataPointVO dataPoint = user.getEditPoint();
    if (dataPoint.getId() == uiPointId) {
        result.addData("match", true);
    } else {
        result.addData("message", Common.translate("pointEdit.error.uiPointMismatch"));
        result.addData("match", false);
    }
    return result;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 78 with ProcessResult

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

the class DataSourceDwr method getCopy.

@DwrPermission(user = true)
@Override
public ProcessResult getCopy(int id) {
    // Get a Full Copy
    DataSourceVO<?> vo = dao.getFull(id);
    ProcessResult response = new ProcessResult();
    String name = StringUtils.abbreviate(TranslatableMessage.translate(getTranslations(), "common.copyPrefix", vo.getName()), 40);
    // Setup the Copy
    DataSourceVO<?> copy = vo.copy();
    copy.setId(Common.NEW_ID);
    copy.setName(name);
    copy.setXid(dao.generateUniqueXid());
    response.addData("vo", copy);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 79 with ProcessResult

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

the class DataSourceDwr method initDataSourceTypes.

/**
 * Init Data Source Types
 *
 * @return
 */
@DwrPermission(user = true)
public ProcessResult initDataSourceTypes() {
    ProcessResult response = new ProcessResult();
    User user = Common.getUser();
    if (user.isDataSourcePermission()) {
        List<StringStringPair> translatedTypes = new ArrayList<>();
        for (String type : ModuleRegistry.getDataSourceDefinitionTypes()) {
            translatedTypes.add(new StringStringPair(type, translate(ModuleRegistry.getDataSourceDefinition(type).getDescriptionKey())));
        }
        StringStringPairComparator.sort(translatedTypes);
        response.addData("types", translatedTypes);
    }
    return response;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 80 with ProcessResult

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

the class DataSourceDwr method getPollTimes.

/**
 * Get the latest poll times and thier durations
 * @param id
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getPollTimes(int id) {
    ProcessResult result = new ProcessResult();
    DataSourceRT ds = Common.runtimeManager.getRunningDataSource(id);
    List<StringStringPair> polls = new ArrayList<StringStringPair>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<LongLongPair> list = ((PollingDataSource) ds).getLatestPollTimes();
        String pollTime;
        for (LongLongPair poll : list) {
            StringBuilder duration = new StringBuilder();
            pollTime = Functions.getFullMilliSecondTime(poll.getKey());
            if (poll.getValue() >= 0) {
                // Format Duration Nicely
                Period period = new Period(poll.getValue());
                if (period.getHours() >= 1) {
                    duration.append(translate("common.duration.hours", period.getHours()));
                    duration.append(SPACE);
                }
                if (period.getMinutes() >= 1) {
                    duration.append(translate("common.duration.minutes", period.getMinutes()));
                    duration.append(SPACE);
                }
                if (period.getSeconds() >= 1) {
                    duration.append(translate("common.duration.seconds", period.getSeconds()));
                    duration.append(SPACE);
                }
                duration.append(translate("common.duration.millis", period.getMillis()));
            } else {
                duration.append(translate("event.ds.pollAborted"));
            }
            StringStringPair pair = new StringStringPair(pollTime, duration.toString());
            polls.add(pair);
        }
    }
    List<String> aborts = new ArrayList<String>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<Long> list = ((PollingDataSource) ds).getLatestAbortedPollTimes();
        String pollTime;
        for (Long poll : list) {
            pollTime = Functions.getFullMilliSecondTime(poll);
            aborts.add(pollTime);
        }
    }
    result.addData("polls", polls);
    result.addData("aborts", aborts);
    return result;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) LongLongPair(com.serotonin.db.pair.LongLongPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)165 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)132 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 User (com.serotonin.m2m2.vo.User)31 ArrayList (java.util.ArrayList)28 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)27 JsonException (com.serotonin.json.JsonException)21 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)20 JsonObject (com.serotonin.json.type.JsonObject)13 HashMap (java.util.HashMap)12 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)11 StringStringPair (com.serotonin.db.pair.StringStringPair)9 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)9 IOException (java.io.IOException)9 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)8 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)8 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)8 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)7 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7