Search in sources :

Example 1 with MangoPermissionModel

use of com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel in project ma-modules-public by infiniteautomation.

the class DataPointModel method fromVO.

@Override
public void fromVO(DataPointVO point) {
    this.id = point.getId();
    this.xid = point.getXid();
    this.name = point.getName();
    this.enabled = point.isEnabled();
    this.deviceName = point.getDeviceName();
    this.readPermission = new MangoPermissionModel(point.getReadPermission());
    this.editPermission = new MangoPermissionModel(point.getEditPermission());
    this.setPermission = new MangoPermissionModel(point.getSetPermission());
    this.purgeOverride = point.isPurgeOverride();
    if (this.purgeOverride) {
        this.purgePeriod = new TimePeriodModel(point.getPurgePeriod(), point.getPurgeType());
    }
    this.unit = JUnitUtil.formatLocal(point.getUnit());
    this.useIntegralUnit = point.isUseIntegralUnit();
    if (this.useIntegralUnit) {
        this.integralUnit = JUnitUtil.formatLocal(point.getIntegralUnit());
    }
    this.useRenderedUnit = point.isUseRenderedUnit();
    if (this.useRenderedUnit) {
        this.renderedUnit = JUnitUtil.formatLocal(point.getRenderedUnit());
    }
    // The Point Locator will be set by the RestModelMapper after
    this.chartColour = point.getChartColour();
    this.plotType = DataPointVO.PLOT_TYPE_CODES.getCode(point.getPlotType());
    this.tags = point.getTags();
    this.loggingProperties = new LoggingPropertiesModel(point);
    this.dataSourceId = point.getDataSourceId();
    this.dataSourceXid = point.getDataSourceXid();
    this.dataSourceName = point.getDataSourceName();
    this.dataSourceTypeName = point.getDataSourceTypeName();
    this.rollup = Common.ROLLUP_CODES.getCode(point.getRollup());
    this.simplifyType = DataPointVO.SIMPLIFY_TYPE_CODES.getCode(point.getSimplifyType());
    this.simplifyTolerance = point.getSimplifyTolerance();
    this.simplifyTarget = point.getSimplifyTarget();
    this.preventSetExtremeValues = point.isPreventSetExtremeValues();
    if (this.preventSetExtremeValues) {
        this.setExtremeLowLimit = point.getSetExtremeLowLimit();
        this.setExtremeHighLimit = point.getSetExtremeHighLimit();
    }
    this.extendedName = point.getExtendedName();
    this.data = point.getData();
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel)

Example 2 with MangoPermissionModel

use of com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel in project ma-modules-public by infiniteautomation.

the class WatchListModelMapping method map.

@Override
public WatchListModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    WatchListVO vo = (WatchListVO) from;
    WatchListModel model = new WatchListModel(vo);
    model.setReadPermission(new MangoPermissionModel(vo.getReadPermission()));
    model.setEditPermission(new MangoPermissionModel(vo.getEditPermission()));
    if (vo.getType() == WatchListType.STATIC) {
        // Set the point summaries
        model.setPoints(vo.getPointList().stream().map(WatchListDataPointModel::new).collect(Collectors.toList()));
    }
    return model;
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 3 with MangoPermissionModel

use of com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel in project ma-modules-public by infiniteautomation.

the class WatchListSummaryModelMapping method map.

@Override
public WatchListSummaryModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    WatchListVO vo = (WatchListVO) from;
    WatchListSummaryModel model = new WatchListSummaryModel(vo);
    model.setReadPermission(new MangoPermissionModel(vo.getReadPermission()));
    model.setEditPermission(new MangoPermissionModel(vo.getEditPermission()));
    return model;
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 4 with MangoPermissionModel

use of com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventModel method fromVO.

@Override
public void fromVO(MaintenanceEventVO vo) {
    super.fromVO(vo);
    if (vo.getDataSources().size() > 0) {
        dataSources = new ArrayList<>();
        for (int id : vo.getDataSources()) {
            String xid = DataSourceDao.getInstance().getXidById(id);
            if (xid != null)
                dataSources.add(xid);
        }
    }
    if (vo.getDataPoints().size() > 0) {
        dataPoints = new ArrayList<>();
        for (int id : vo.getDataPoints()) {
            String xid = DataPointDao.getInstance().getXidById(id);
            if (xid != null)
                dataPoints.add(xid);
        }
    }
    alarmLevel = vo.getAlarmLevel();
    scheduleType = MaintenanceEventVO.TYPE_CODES.getCode(vo.getScheduleType());
    disabled = vo.isDisabled();
    activeYear = vo.getActiveYear();
    activeMonth = vo.getActiveMonth();
    activeDay = vo.getActiveDay();
    activeHour = vo.getActiveHour();
    activeMinute = vo.getActiveMinute();
    activeSecond = vo.getActiveMinute();
    activeCron = vo.getActiveCron();
    inactiveYear = vo.getInactiveYear();
    inactiveMonth = vo.getInactiveMonth();
    inactiveDay = vo.getInactiveDay();
    inactiveHour = vo.getInactiveHour();
    inactiveMinute = vo.getInactiveMinute();
    inactiveSecond = vo.getInactiveSecond();
    inactiveCron = vo.getInactiveCron();
    timeoutPeriods = vo.getTimeoutPeriods();
    timeoutPeriodType = Common.TIME_PERIOD_CODES.getCode(vo.getTimeoutPeriodType());
    togglePermission = new MangoPermissionModel(vo.getTogglePermission());
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel)

Example 5 with MangoPermissionModel

use of com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel in project ma-modules-public by infiniteautomation.

the class MangoPermissionModelDeserializer method nodeToModel.

@SuppressWarnings("unchecked")
public MangoPermissionModel nodeToModel(JsonNode tree, ObjectMapper mapper) throws JsonProcessingException {
    Set<Set<Role>> roles = new HashSet<>();
    if (tree instanceof ArrayNode) {
        Set<Object> outerSet = mapper.treeToValue(tree, Set.class);
        for (Object o : outerSet) {
            Set<Role> innerRoles = new HashSet<>();
            roles.add(innerRoles);
            if (o instanceof Iterable) {
                for (String xid : (Iterable<String>) o) {
                    Role role = permissionService.getRole(xid);
                    if (role != null) {
                        innerRoles.add(role);
                    } else {
                        // Let validation pick this up
                        innerRoles.add(new Role(Common.NEW_ID, xid));
                    }
                }
            } else {
                String xid = (String) o;
                Role role = permissionService.getRole(xid);
                if (role != null) {
                    innerRoles.add(role);
                } else {
                    // Let validation pick this up
                    innerRoles.add(new Role(Common.NEW_ID, xid));
                }
            }
        }
    } else if (tree instanceof TextNode) {
        Set<String> xids = PermissionService.explodeLegacyPermissionGroups(tree.asText());
        for (String xid : xids) {
            Role role = permissionService.getRole(xid);
            if (role != null) {
                roles.add(Collections.singleton(role));
            } else {
                // Let validation pick this up
                roles.add(Collections.singleton(new Role(Common.NEW_ID, xid)));
            }
        }
    }
    return new MangoPermissionModel(new MangoPermission(roles));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TextNode(com.fasterxml.jackson.databind.node.TextNode) Role(com.serotonin.m2m2.vo.role.Role) MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Aggregations

MangoPermissionModel (com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel)12 Role (com.serotonin.m2m2.vo.role.Role)2 WatchListVO (com.serotonin.m2m2.watchlist.WatchListVO)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)1 EventTypeMatcherModel (com.infiniteautomation.mango.rest.latest.model.event.EventTypeMatcherModel)1 TimePeriod (com.infiniteautomation.mango.rest.latest.model.time.TimePeriod)1 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 RTException (com.serotonin.m2m2.rt.RTException)1 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)1 ExportCodes (com.serotonin.m2m2.util.ExportCodes)1 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)1 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)1 MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1