Search in sources :

Example 6 with MangoPermissionModel

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

the class MailingListModelMapping method map.

@Override
public MailingListModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    MailingList vo = (MailingList) from;
    MailingListModel model;
    if (mailingListService.hasRecipientViewPermission(user, vo)) {
        model = new MailingListWithRecipientsModel(vo);
        if (vo.getEntries() != null && vo.getEntries().size() > 0) {
            List<EmailRecipientModel> recipients = new ArrayList<>();
            ((MailingListWithRecipientsModel) model).setRecipients(recipients);
            for (MailingListRecipient entry : vo.getEntries()) {
                recipients.add(mapper.map(entry, EmailRecipientModel.class, user));
            }
        }
    } else {
        model = new MailingListModel(vo);
    }
    model.setReadPermissions(new MangoPermissionModel(vo.getReadPermission()));
    model.setEditPermissions(new MangoPermissionModel(vo.getEditPermission()));
    return model;
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient)

Example 7 with MangoPermissionModel

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

the class UserModel method fromVO.

@Override
public void fromVO(User vo) {
    super.fromVO(vo);
    this.username = vo.getUsername();
    this.password = vo.getPassword();
    this.email = vo.getEmail();
    this.phone = vo.getPhone();
    this.disabled = vo.isDisabled();
    this.homeUrl = vo.getHomeUrl();
    this.lastLogin = vo.getLastLogin() == 0 ? null : new Date(vo.getLastLogin());
    this.lastPasswordChange = new Date(vo.getPasswordChangeTimestamp());
    this.receiveAlarmEmails = vo.getReceiveAlarmEmails();
    this.timezone = StringUtils.isBlank(vo.getTimezone()) ? null : vo.getTimezone();
    this.muted = vo.isMuted();
    this.receiveOwnAuditEvents = vo.isReceiveOwnAuditEvents();
    this.roles = new HashSet<>();
    for (Role role : vo.getRoles()) {
        roles.add(role.getXid());
    }
    // TODO move this into the model mapper and use map/unmap anywhere
    // a user model is needed
    PermissionService permissionService = Common.getBean(PermissionService.class);
    this.inheritedRoles = new HashSet<>();
    Set<Role> getAllInheritedRoles = permissionService.getAllInheritedRoles(vo);
    for (Role role : getAllInheritedRoles) {
        this.inheritedRoles.add(role.getXid());
    }
    this.systemPermissions = permissionService.getSystemPermissions(vo);
    this.locale = StringUtils.isBlank(vo.getLocale()) ? null : vo.getLocale();
    this.passwordLocked = vo.isPasswordLocked();
    this.sessionExpirationOverride = vo.isSessionExpirationOverride();
    if (sessionExpirationOverride)
        this.sessionExpirationPeriod = new TimePeriod(vo.getSessionExpirationPeriods(), TimePeriodType.valueOf(vo.getSessionExpirationPeriodType()));
    this.organization = vo.getOrganization();
    this.organizationalRole = vo.getOrganizationalRole();
    this.created = vo.getCreated();
    this.emailVerified = vo.getEmailVerifiedDate();
    this.data = vo.getData();
    this.editPermission = new MangoPermissionModel(vo.getEditPermission());
    this.readPermission = new MangoPermissionModel(vo.getReadPermission());
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) TimePeriod(com.infiniteautomation.mango.rest.latest.model.time.TimePeriod) MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) Date(java.util.Date)

Example 8 with MangoPermissionModel

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

the class FileStoreModel method fromVO.

@Override
public void fromVO(FileStore vo) {
    super.fromVO(vo);
    this.readPermission = new MangoPermissionModel(vo.getReadPermission());
    this.writePermission = new MangoPermissionModel(vo.getWritePermission());
    this.builtIn = vo.isBuiltIn();
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel)

Example 9 with MangoPermissionModel

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

the class JsonDataModel method fromVO.

@Override
public void fromVO(JsonDataVO vo) {
    super.fromVO(vo);
    this.readPermission = new MangoPermissionModel(vo.getReadPermission());
    this.editPermission = new MangoPermissionModel(vo.getEditPermission());
    this.jsonData = vo.getJsonData();
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel)

Example 10 with MangoPermissionModel

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

the class AbstractDataSourceModel method fromVO.

@Override
public void fromVO(T vo) {
    super.fromVO(vo);
    this.connectionDescription = vo.getConnectionDescription();
    this.description = new TranslatableMessage(vo.getDefinition().getDescriptionKey());
    this.enabled = vo.isEnabled();
    this.eventAlarmLevels = new ArrayList<>();
    ExportCodes eventCodes = vo.getEventCodes();
    for (EventTypeVO evt : vo.getEventTypes()) {
        DataSourceEventType dsEvt = (DataSourceEventType) evt.getEventType();
        EventTypeAlarmLevelModel model = new EventTypeAlarmLevelModel(eventCodes.getCode(dsEvt.getReferenceId2()), dsEvt.getDuplicateHandling(), dsEvt.getAlarmLevel(), evt.getDescription());
        this.eventAlarmLevels.add(model);
    }
    this.purgeSettings = new PurgeSettings(vo);
    this.editPermission = new MangoPermissionModel(vo.getEditPermission());
    this.readPermission = new MangoPermissionModel(vo.getReadPermission());
    this.data = vo.getData();
    try {
        DataSourceRT<?> rt = Common.runtimeManager.getRunningDataSource(getId());
        this.lifecycleState = rt.getLifecycleState();
    } catch (RTException e) {
        this.lifecycleState = ILifecycleState.TERMINATED;
    }
}
Also used : DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) RTException(com.serotonin.m2m2.rt.RTException) ExportCodes(com.serotonin.m2m2.util.ExportCodes) MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO)

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