Search in sources :

Example 91 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 92 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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)

Example 93 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class ModulesDwr method scheduleShutdown.

@DwrPermission(admin = true)
public static ProcessResult scheduleShutdown() {
    ProcessResult result = new ProcessResult();
    synchronized (SHUTDOWN_TASK_LOCK) {
        if (SHUTDOWN_TASK == null) {
            long timeout = Common.getMillis(Common.TimePeriods.SECONDS, 10);
            // Ensure our lifecycle state is set to PRE_SHUTDOWN
            IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
            SHUTDOWN_TASK = lifecycle.scheduleShutdown(timeout, false, Common.getHttpUser());
            // Get the redirect page
            result.addData("shutdownUri", "/shutdown.htm");
        } else {
            result.addData("message", Common.translate("modules.shutdownAlreadyScheduled"));
        }
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 94 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class PublisherListDwr method togglePublisher.

@DwrPermission(admin = true)
public ProcessResult togglePublisher(int publisherId) {
    ProcessResult response = new ProcessResult();
    PublisherVO<? extends PublishedPointVO> publisher = Common.runtimeManager.getPublisher(publisherId);
    publisher.setEnabled(!publisher.isEnabled());
    publisher.validate(response);
    if (!response.getHasMessages())
        Common.runtimeManager.savePublisher(publisher);
    else
        publisher.setEnabled(!publisher.isEnabled());
    response.addData("enabled", publisher.isEnabled());
    response.addData("id", publisherId);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 95 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class StartupDwr method getStartupProgress.

@DwrPermission(anonymous = true)
public ProcessResult getStartupProgress(long since) {
    ProcessResult result = new ProcessResult();
    IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
    float progress = lifecycle.getStartupProgress();
    float shutdownProgress = lifecycle.getShutdownProgress();
    List<String> messages = LoggingConsoleRT.instance.getMessagesSince(since);
    StringBuilder builder = new StringBuilder();
    for (String message : messages) {
        builder.append(message);
        builder.append("</br>");
    }
    result.addData("message", builder.toString());
    result.addData("startupProgress", progress);
    result.addData("shutdownProgress", shutdownProgress);
    result.addData("state", getLifecycleStateMessage(lifecycle.getLifecycleState()));
    if ((progress >= 100) && (shutdownProgress == 0)) {
        WebContext ctx = WebContextFactory.get();
        result.addData("startupUri", DefaultPagesDefinition.getLoginUri(ctx.getHttpServletRequest(), ctx.getHttpServletResponse()));
    }
    // Add the message to describe what process we are in
    if ((progress < 100) && (shutdownProgress == 0)) {
        result.addData("processMessage", this.translations.translate("startup.startingUp"));
    } else if ((shutdownProgress > 0) && (lifecycle.isRestarting())) {
        result.addData("processMessage", this.translations.translate("shutdown.restarting"));
    } else if (shutdownProgress > 0) {
        result.addData("processMessage", this.translations.translate("shutdown.shuttingDown"));
    }
    if ((progress == 100) && (shutdownProgress == 0)) {
        result.addData("processMessage", this.translations.translate("startup.state.running"));
    }
    return result;
}
Also used : WebContext(org.directwebremoting.WebContext) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6