Search in sources :

Example 1 with TableModel

use of com.infiniteautomation.mango.db.query.TableModel in project ma-modules-public by infiniteautomation.

the class AbstractMangoVoRestV2Controller method getQueryAttributeModel.

/**
 * Get the Table Model
 * @return
 */
protected TableModel getQueryAttributeModel() {
    TableModel model = this.dao.getTableModel();
    // Add in our mappings
    Iterator<String> it = this.modelMap.keySet().iterator();
    while (it.hasNext()) {
        String modelMember = it.next();
        String mappedTo = this.modelMap.get(modelMember);
        for (QueryAttribute attribute : model.getAttributes()) {
            if (attribute.getColumnName().equals(mappedTo)) {
                attribute.addAlias(modelMember);
            }
        }
    }
    return model;
}
Also used : QueryAttribute(com.infiniteautomation.mango.db.query.QueryAttribute) TableModel(com.infiniteautomation.mango.db.query.TableModel)

Example 2 with TableModel

use of com.infiniteautomation.mango.db.query.TableModel in project ma-core-public by infiniteautomation.

the class MangoVoRestController method getQueryAttributeModel.

/**
 * Get the Table Model
 * @return
 */
protected TableModel getQueryAttributeModel() {
    TableModel model = this.dao.getTableModel();
    // Add in our mappings
    Iterator<String> it = this.modelMap.keySet().iterator();
    while (it.hasNext()) {
        String modelMember = it.next();
        String mappedTo = this.modelMap.get(modelMember);
        for (QueryAttribute attribute : model.getAttributes()) {
            if (attribute.getColumnName().equals(mappedTo)) {
                attribute.addAlias(modelMember);
            }
        }
    }
    return model;
}
Also used : QueryAttribute(com.infiniteautomation.mango.db.query.QueryAttribute) TableModel(com.infiniteautomation.mango.db.query.TableModel)

Example 3 with TableModel

use of com.infiniteautomation.mango.db.query.TableModel in project ma-modules-public by infiniteautomation.

the class UserEventsV2Controller 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) {
    Map<String, QueryAttribute> attributeMap = new HashMap<>();
    Field[] inherited = EventInstance.class.getFields();
    for (Field field : inherited) {
        QueryAttribute qa = new QueryAttribute(field.getName(), null, getJdbcTypeCode(field.getGenericType().getTypeName()));
        attributeMap.put(field.getName(), qa);
    }
    Field[] all = EventInstance.class.getDeclaredFields();
    for (Field field : all) {
        QueryAttribute qa = new QueryAttribute(field.getName(), null, getJdbcTypeCode(field.getGenericType().getTypeName()));
        attributeMap.put(field.getName(), qa);
    }
    return new ResponseEntity<>(new TableModel("EventInstance.class", new ArrayList<>(attributeMap.values())), HttpStatus.OK);
}
Also used : Field(java.lang.reflect.Field) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) 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 4 with TableModel

use of com.infiniteautomation.mango.db.query.TableModel 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)

Aggregations

QueryAttribute (com.infiniteautomation.mango.db.query.QueryAttribute)4 TableModel (com.infiniteautomation.mango.db.query.TableModel)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 ResponseEntity (org.springframework.http.ResponseEntity)1