Search in sources :

Example 1 with QueryAttribute

use of com.infiniteautomation.mango.db.query.QueryAttribute 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 2 with QueryAttribute

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

the class DataPointDao method getIndexes.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.db.dao.AbstractBasicDao#getIndexes()
     */
@Override
protected List<Index> getIndexes() {
    List<Index> indexes = new ArrayList<Index>();
    List<QueryAttribute> columns = new ArrayList<QueryAttribute>();
    // Data Source Name Force
    columns.add(new QueryAttribute("name", new HashSet<String>(), Types.VARCHAR));
    indexes.add(new Index("nameIndex", "ds", columns, "ASC"));
    // Data Source xid Force
    columns = new ArrayList<QueryAttribute>();
    columns.add(new QueryAttribute("xid", new HashSet<String>(), Types.VARCHAR));
    indexes.add(new Index("dataSourcesUn1", "ds", columns, "ASC"));
    // DeviceNameName Index Force
    columns = new ArrayList<QueryAttribute>();
    columns.add(new QueryAttribute("deviceName", new HashSet<String>(), Types.VARCHAR));
    columns.add(new QueryAttribute("name", new HashSet<String>(), Types.VARCHAR));
    indexes.add(new Index("deviceNameNameIndex", "dp", columns, "ASC"));
    // xid point name force
    columns = new ArrayList<QueryAttribute>();
    columns.add(new QueryAttribute("xid", new HashSet<String>(), Types.VARCHAR));
    columns.add(new QueryAttribute("name", new HashSet<String>(), Types.VARCHAR));
    indexes.add(new Index("xidNameIndex", "dp", columns, "ASC"));
    return indexes;
}
Also used : ArrayList(java.util.ArrayList) QueryAttribute(com.infiniteautomation.mango.db.query.QueryAttribute) Index(com.infiniteautomation.mango.db.query.Index) HashSet(java.util.HashSet)

Example 3 with QueryAttribute

use of com.infiniteautomation.mango.db.query.QueryAttribute 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 4 with QueryAttribute

use of com.infiniteautomation.mango.db.query.QueryAttribute 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 5 with QueryAttribute

use of com.infiniteautomation.mango.db.query.QueryAttribute 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)5 TableModel (com.infiniteautomation.mango.db.query.TableModel)4 ArrayList (java.util.ArrayList)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Index (com.infiniteautomation.mango.db.query.Index)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ResponseEntity (org.springframework.http.ResponseEntity)1