Search in sources :

Example 76 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class PermissionService method get.

/**
 * Get a permission from the cache, load from db if necessary
 * @param id
 * @return
 * @throws NotFoundException if permission with this ID not found
 */
public MangoPermission get(Integer id) throws NotFoundException {
    Objects.requireNonNull(id);
    MangoPermission permission = permissionCache.computeIfAbsent(id, this::loadPermission);
    if (permission == null) {
        throw new NotFoundException();
    } else {
        return permission.withId(id);
    }
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 77 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class DataPointService method getReadPermission.

/**
 * Get the read permission for this data point
 */
public MangoPermission getReadPermission(int dataPointId) throws NotFoundException, PermissionException {
    PermissionHolder user = Common.getUser();
    Integer permissionId = dao.getReadPermissionId(dataPointId);
    if (permissionId == null) {
        throw new NotFoundException();
    }
    MangoPermission read = permissionService.get(permissionId);
    permissionService.ensurePermission(user, read);
    return read;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 78 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class EventInstanceDao method savePreRelationalData.

@Override
public void savePreRelationalData(EventInstanceVO existing, EventInstanceVO vo) {
    MangoPermission readPermission = permissionService.findOrCreate(vo.getReadPermission());
    vo.setReadPermission(readPermission);
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 79 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class EventInstanceDao method mapRecord.

@Override
@NonNull
public EventInstanceVO mapRecord(@NonNull Record record) {
    EventInstanceVO event = new EventInstanceVO();
    event.setId(record.get(table.id));
    EventType type = createEventType(record);
    event.setEventType(type);
    event.setActiveTimestamp(record.get(table.activeTs));
    event.setRtnApplicable(charToBool(record.get(table.rtnApplicable)));
    event.setAlarmLevel(AlarmLevels.fromValue(record.get(table.alarmLevel)));
    TranslatableMessage message = BaseDao.readTranslatableMessage(record.get(table.message));
    if (message == null)
        event.setMessage(new TranslatableMessage("common.noMessage"));
    else
        event.setMessage(message);
    // Set the Return to normal
    Long rtnTs = record.get(table.rtnTs);
    if (rtnTs != null) {
        // if(event.isActive()){ Probably don't need this
        event.setRtnTimestamp(rtnTs);
        event.setRtnCause(ReturnCause.fromValue(record.get(table.rtnCause)));
    // }
    }
    MangoPermission read = new MangoPermission(record.get(table.readPermissionId));
    event.supplyReadPermission(() -> read);
    Long ackTs = record.get(table.ackTs);
    if (ackTs != null) {
        // Compute total time
        event.setAcknowledgedTimestamp(ackTs);
        Integer ackUserId = record.get(table.ackUserId);
        if (ackUserId != null) {
            event.setAcknowledgedByUserId(ackUserId);
            event.setAcknowledgedByUsername(record.get(users.username));
        }
        event.setAlternateAckSource(BaseDao.readTranslatableMessage(record.get(table.alternateAckSource)));
    }
    event.setHasComments(record.get(commentCount) > 0);
    return event;
}
Also used : EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) MissingEventType(com.serotonin.m2m2.rt.event.type.MissingEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 80 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.

the class MailingListDao method savePreRelationalData.

@Override
public void savePreRelationalData(MailingList existing, MailingList vo) {
    MangoPermission readPermission = permissionService.findOrCreate(vo.getReadPermission());
    vo.setReadPermission(readPermission);
    MangoPermission editPermission = permissionService.findOrCreate(vo.getEditPermission());
    vo.setEditPermission(editPermission);
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Aggregations

MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)93 Role (com.serotonin.m2m2.vo.role.Role)22 HashSet (java.util.HashSet)21 Set (java.util.Set)18 HashMap (java.util.HashMap)13 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)12 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)11 JsonException (com.serotonin.json.JsonException)10 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)9 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)8 JsonValue (com.serotonin.json.type.JsonValue)7 ArrayList (java.util.ArrayList)7 JsonArray (com.serotonin.json.type.JsonArray)6 JsonObject (com.serotonin.json.type.JsonObject)6 User (com.serotonin.m2m2.vo.User)6 OutputStream (java.io.OutputStream)5 Test (org.junit.Test)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4