Search in sources :

Example 1 with RoleVO

use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.

the class RoleRestController method update.

@ApiOperation(value = "Update a Role List", notes = "Admin only")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<RoleModel> update(@ApiParam(value = "XID of Role to update", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Role List of update", required = true, allowMultiple = false) @RequestBody RoleModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    RoleVO vo = service.update(xid, mapping.unmap(model, user, mapper));
    URI location = builder.path("/roles/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RoleVO

use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.

the class RoleRestController method partialUpdate.

@ApiOperation(value = "Partially update a Role", notes = "Admin only")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<RoleModel> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated role", required = true) @PatchVORequestBody(service = RoleService.class, modelClass = RoleModel.class) RoleModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    RoleVO vo = service.update(xid, mapping.unmap(model, user, mapper));
    URI location = builder.path("/roles/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RoleVO

use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.

the class RoleModelMapping method map.

@Override
public RoleModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    RoleVO role = (RoleVO) from;
    RoleModel model = new RoleModel(role);
    if (role.getInherited() != null) {
        Set<String> inherited = new HashSet<>(role.getInherited().size());
        model.setInherited(inherited);
        for (Role inheritedRole : role.getInherited()) {
            inherited.add(inheritedRole.getXid());
        }
    }
    return model;
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) HashSet(java.util.HashSet)

Example 4 with RoleVO

use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.

the class PermissionService method loadRoleInheritance.

private RoleInheritance loadRoleInheritance(String xid) {
    RoleInheritance i = new RoleInheritance();
    RoleVO roleVo = roleDao.getByXid(xid);
    if (roleVo == null) {
        return null;
    }
    i.role = roleVo.getRole();
    i.inherited = roleDao.getFlatInheritance(roleVo.getRole());
    i.inheritedBy = roleDao.getRolesThatInherit(roleVo.getRole());
    return i;
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO)

Example 5 with RoleVO

use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.

the class H2DatabaseTest method test1AutoIncrement.

@Test
public void test1AutoIncrement() throws SQLException {
    DSLContext context = Common.getBean(DatabaseProxy.class).getContext();
    Roles r = Roles.ROLES;
    context.insertInto(r, r.id, r.xid, r.name).values(10, "xid", "name").execute();
    context.insertInto(r, r.xid, r.name).values("test", "test").execute();
    RoleVO role = Common.getBean(RoleDao.class).getByXid("test");
    assertEquals(11, role.getId());
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) DSLContext(org.jooq.DSLContext) Roles(com.infiniteautomation.mango.db.tables.Roles) Test(org.junit.Test)

Aggregations

RoleVO (com.serotonin.m2m2.vo.role.RoleVO)32 Role (com.serotonin.m2m2.vo.role.Role)18 Test (org.junit.Test)17 HashSet (java.util.HashSet)10 RoleService (com.infiniteautomation.mango.spring.service.RoleService)7 User (com.serotonin.m2m2.vo.User)6 ArrayList (java.util.ArrayList)6 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)4 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)4 JsonValue (com.serotonin.json.type.JsonValue)4 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 Roles (com.infiniteautomation.mango.db.tables.Roles)3 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)3 JsonException (com.serotonin.json.JsonException)3 JsonObject (com.serotonin.json.type.JsonObject)3 Set (java.util.Set)3 DSLContext (org.jooq.DSLContext)3 ImportContext (com.infiniteautomation.mango.emport.ImportContext)2 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)2