Search in sources :

Example 36 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class LoggingRestController method getTableModel.

@ApiOperation(value = "Get Explaination For Query", notes = "What is Query-able on this model")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok"), @ApiResponse(code = 403, message = "User does not have access") })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/explain-query")
public ResponseEntity<TableModel> getTableModel(HttpServletRequest request) {
    RestProcessResult<TableModel> result = new RestProcessResult<TableModel>(HttpStatus.OK);
    this.checkUser(request, result);
    if (result.isOk()) {
        TableModel model = new TableModel();
        List<QueryAttribute> attributes = new ArrayList<QueryAttribute>();
        attributes.add(new QueryAttribute("level", null, Types.VARCHAR));
        attributes.add(new QueryAttribute("classname", null, Types.VARCHAR));
        attributes.add(new QueryAttribute("method", null, Types.VARCHAR));
        attributes.add(new QueryAttribute("time", null, Types.INTEGER));
        attributes.add(new QueryAttribute("message", null, Types.VARCHAR));
        model.setAttributes(attributes);
        result.addRestMessage(getSuccessMessage());
        return result.createResponseEntity();
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryAttribute(com.infiniteautomation.mango.db.query.QueryAttribute) ArrayList(java.util.ArrayList) TableModel(com.infiniteautomation.mango.db.query.TableModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class UserRestController method getUserPermissions.

@ApiOperation(value = "Get User Permissions Information for all users", notes = "", response = PermissionDetails.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = PermissionDetails.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/permissions")
public ResponseEntity<List<PermissionDetails>> getUserPermissions(HttpServletRequest request) {
    RestProcessResult<List<PermissionDetails>> result = new RestProcessResult<List<PermissionDetails>>(HttpStatus.OK);
    User currentUser = this.checkUser(request, result);
    if (result.isOk()) {
        List<PermissionDetails> ds = new ArrayList<>();
        for (User user : UserDao.instance.getActiveUsers()) {
            PermissionDetails deets = Permissions.getPermissionDetails(currentUser, null, user);
            if (deets != null)
                ds.add(deets);
        }
        return result.createResponseEntity(ds);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) PermissionDetails(com.serotonin.m2m2.vo.permission.PermissionDetails) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class UserRestController method getAllUserGroups.

@ApiOperation(value = "Get All User Groups that a user can 'see', Optionally excluding groups", notes = "", response = String.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = String.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/permissions-groups/{exclude}")
public ResponseEntity<Set<String>> getAllUserGroups(@ApiParam(value = "Exclude Groups comma separated", required = false, allowMultiple = false, defaultValue = "") @PathVariable String exclude, HttpServletRequest request) {
    RestProcessResult<Set<String>> result = new RestProcessResult<Set<String>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        Set<String> groups = new TreeSet<>();
        if (user.isAdmin()) {
            for (User u : UserDao.instance.getActiveUsers()) groups.addAll(Permissions.explodePermissionGroups(u.getPermissions()));
        } else {
            groups.addAll(Permissions.explodePermissionGroups(user.getPermissions()));
        }
        if (!StringUtils.isEmpty(exclude)) {
            for (String part : exclude.split(",")) groups.remove(part);
        }
        return result.createResponseEntity(groups);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) TreeSet(java.util.TreeSet) Set(java.util.Set) User(com.serotonin.m2m2.vo.User) TreeSet(java.util.TreeSet) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class UserRestController method getAllUserGroups.

@ApiOperation(value = "Get All User Groups that a user can 'see'", notes = "", response = String.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = String.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/permissions-groups")
public ResponseEntity<Set<String>> getAllUserGroups(HttpServletRequest request) {
    RestProcessResult<Set<String>> result = new RestProcessResult<Set<String>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        Set<String> groups = new TreeSet<>();
        if (user.isAdmin()) {
            for (User u : UserDao.instance.getActiveUsers()) groups.addAll(Permissions.explodePermissionGroups(u.getPermissions()));
        } else {
            groups.addAll(Permissions.explodePermissionGroups(user.getPermissions()));
        }
        return result.createResponseEntity(groups);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) TreeSet(java.util.TreeSet) Set(java.util.Set) User(com.serotonin.m2m2.vo.User) TreeSet(java.util.TreeSet) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project ma-modules-public by infiniteautomation.

the class UserRestController method getUserPermissions.

@ApiOperation(value = "Get User Permissions Information for all users, exclude provided groups in query", notes = "", response = PermissionDetails.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = PermissionDetails.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/permissions/{query}")
public ResponseEntity<List<PermissionDetails>> getUserPermissions(@ApiParam(value = "Query of permissions to show as already added", required = true, allowMultiple = false) @PathVariable String query, HttpServletRequest request) {
    RestProcessResult<List<PermissionDetails>> result = new RestProcessResult<List<PermissionDetails>>(HttpStatus.OK);
    User currentUser = this.checkUser(request, result);
    if (result.isOk()) {
        List<PermissionDetails> ds = new ArrayList<>();
        for (User user : UserDao.instance.getActiveUsers()) {
            PermissionDetails deets = Permissions.getPermissionDetails(currentUser, query, user);
            if (deets != null)
                ds.add(deets);
        }
        return result.createResponseEntity(ds);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) PermissionDetails(com.serotonin.m2m2.vo.permission.PermissionDetails) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiResponses (com.wordnik.swagger.annotations.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)44 Path (javax.ws.rs.Path)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 Produces (javax.ws.rs.Produces)17 POST (javax.ws.rs.POST)14 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)13 IOException (java.io.IOException)10 User (com.serotonin.m2m2.vo.User)9 Consumes (javax.ws.rs.Consumes)9 GET (javax.ws.rs.GET)9 ArrayList (java.util.ArrayList)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)6 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 ResponseEntity (org.springframework.http.ResponseEntity)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)4