Skip to content

Commit

Permalink
JBPM-5071 - additional changes for group and datasets (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
mswiderski authored and cristianonicolai committed Jun 27, 2016
1 parent 2d0f6ef commit b0aa884
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 11 deletions.
@@ -0,0 +1,96 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.kie.services.impl.query;

import java.io.Serializable;

import org.dashbuilder.dataset.group.AggregateFunctionType;

public class AggregateColumnFilter implements Serializable {

private static final long serialVersionUID = -3715417647758217121L;

private AggregateFunctionType type;
private String columnId;
private String newColumnId;

public AggregateColumnFilter(AggregateFunctionType type, String columnId, String newColumnId) {
this.type = type;
this.columnId = columnId;
this.newColumnId = newColumnId;
}

public AggregateFunctionType getType() {
return type;
}

public void setType(AggregateFunctionType type) {
this.type = type;
}

public String getColumnId() {
return columnId;
}

public void setColumnId(String columnId) {
this.columnId = columnId;
}


public String getNewColumnId() {
return newColumnId;
}


public void setNewColumnId(String newColumnId) {
this.newColumnId = newColumnId;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((columnId == null) ? 0 : columnId.hashCode());
result = prime * result + ((newColumnId == null) ? 0 : newColumnId.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AggregateColumnFilter other = (AggregateColumnFilter) obj;
if (columnId == null) {
if (other.columnId != null)
return false;
} else if (!columnId.equals(other.columnId))
return false;
if (newColumnId == null) {
if (other.newColumnId != null)
return false;
} else if (!newColumnId.equals(other.newColumnId))
return false;
if (type != other.type)
return false;
return true;
}
}
Expand Up @@ -16,14 +16,14 @@


package org.jbpm.kie.services.impl.query; package org.jbpm.kie.services.impl.query;


import org.dashbuilder.dataset.filter.ColumnFilter;
import org.dashbuilder.dataset.filter.CoreFunctionFilter; import org.dashbuilder.dataset.filter.CoreFunctionFilter;
import org.dashbuilder.dataset.filter.CoreFunctionType; import org.dashbuilder.dataset.filter.CoreFunctionType;
import org.dashbuilder.dataset.group.AggregateFunctionType;
import org.jbpm.services.api.query.QueryParamBuilder; import org.jbpm.services.api.query.QueryParamBuilder;
import org.jbpm.services.api.query.model.QueryParam; import org.jbpm.services.api.query.model.QueryParam;




public class CoreFunctionQueryParamBuilder implements QueryParamBuilder<ColumnFilter> { public class CoreFunctionQueryParamBuilder implements QueryParamBuilder<Object> {


private QueryParam[] filterParams; private QueryParam[] filterParams;
private int index = 0; private int index = 0;
Expand All @@ -32,18 +32,30 @@ public CoreFunctionQueryParamBuilder(QueryParam...filterParams) {
this.filterParams = filterParams; this.filterParams = filterParams;
} }
@Override @Override
public ColumnFilter build() { public Object build() {
if (filterParams.length == 0 || filterParams.length <= index) { if (filterParams.length == 0 || filterParams.length <= index) {
return null; return null;
} }
QueryParam param = filterParams[index]; QueryParam param = filterParams[index];
index++; index++;

if ("group".equalsIgnoreCase(param.getOperator())) {
// if operator is group consider it as group functions
return new GroupColumnFilter(param.getColumn(), (String)param.getValue().get(0));
}
// check core functions
CoreFunctionType type = CoreFunctionType.getByName(param.getOperator()); CoreFunctionType type = CoreFunctionType.getByName(param.getOperator());
if (type == null) { if (type != null) {
throw new IllegalArgumentException("Not supported core function type - " + param.getOperator()); return new CoreFunctionFilter(param.getColumn(), type, param.getValue());
} }
return new CoreFunctionFilter(param.getColumn(), type, param.getValue()); // check aggregate functions
AggregateFunctionType aggregationType = AggregateFunctionType.getByName(param.getOperator());

if (aggregationType != null) {

return new AggregateColumnFilter(aggregationType, param.getColumn(), (String)param.getValue().get(0));
}

return new ExtraColumnFilter(param.getColumn(), (String)param.getValue().get(0));
} }


} }
@@ -0,0 +1,48 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.kie.services.impl.query;

import java.io.Serializable;

public class ExtraColumnFilter implements Serializable {

private static final long serialVersionUID = -3715417647758217121L;

private String newColumnId;
private String columnId;

public ExtraColumnFilter(String columnId, String newColumnId) {
this.columnId = columnId;
this.newColumnId = newColumnId;
}

public String getNewColumnId() {
return newColumnId;
}

public void setNewColumnId(String newColumnId) {
this.newColumnId = newColumnId;
}

public String getColumnId() {
return columnId;
}

public void setColumnId(String columnId) {
this.columnId = columnId;
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.kie.services.impl.query;

import java.io.Serializable;

public class GroupColumnFilter implements Serializable {

private static final long serialVersionUID = -3715417647758217121L;

private String newColumnId;
private String columnId;

public GroupColumnFilter(String columnId, String newColumnId) {
this.columnId = columnId;
this.newColumnId = newColumnId;
}

public String getNewColumnId() {
return newColumnId;
}

public void setNewColumnId(String newColumnId) {
this.newColumnId = newColumnId;
}

public String getColumnId() {
return columnId;
}

public void setColumnId(String columnId) {
this.columnId = columnId;
}
}
Expand Up @@ -28,6 +28,7 @@
import org.dashbuilder.dataset.DataSetLookupBuilder; import org.dashbuilder.dataset.DataSetLookupBuilder;
import org.dashbuilder.dataset.DataSetLookupFactory; import org.dashbuilder.dataset.DataSetLookupFactory;
import org.dashbuilder.dataset.DataSetManager; import org.dashbuilder.dataset.DataSetManager;
import org.dashbuilder.dataset.DataSetMetadata;
import org.dashbuilder.dataset.def.DataSetDef; import org.dashbuilder.dataset.def.DataSetDef;
import org.dashbuilder.dataset.def.DataSetDefFactory; import org.dashbuilder.dataset.def.DataSetDefFactory;
import org.dashbuilder.dataset.def.DataSetDefRegistry; import org.dashbuilder.dataset.def.DataSetDefRegistry;
Expand Down Expand Up @@ -139,15 +140,18 @@ public void replaceQuery(QueryDefinition queryDefinition) {


DataSetDef sqlDef = builder.buildDef(); DataSetDef sqlDef = builder.buildDef();



dataSetDefRegistry.registerDataSetDef(sqlDef); dataSetDefRegistry.registerDataSetDef(sqlDef);


if (queryDefinition.getTarget().equals(Target.BA_TASK)) { if (queryDefinition.getTarget().equals(Target.BA_TASK)) {
dataSetDefRegistry.registerPreprocessor(sqlDef.getUUID(), new BusinessAdminTasksPreprocessor(identityProvider)); dataSetDefRegistry.registerPreprocessor(sqlDef.getUUID(), new BusinessAdminTasksPreprocessor(identityProvider));
} else if (queryDefinition.getTarget().equals(Target.PO_TASK)) { } else if (queryDefinition.getTarget().equals(Target.PO_TASK)) {
dataSetDefRegistry.registerPreprocessor(sqlDef.getUUID(), new PotOwnerTasksPreprocessor(identityProvider)); dataSetDefRegistry.registerPreprocessor(sqlDef.getUUID(), new PotOwnerTasksPreprocessor(identityProvider));
} }

DataSetMetadata metadata = dataSetManager.getDataSetMetadata(sqlDef.getUUID());
for (String columnId : metadata.getColumnIds()) {
sqlDef.addColumn(columnId, metadata.getColumnType(columnId));
}

logger.info("Registered {} query successfully", queryDefinition.getName()); logger.info("Registered {} query successfully", queryDefinition.getName());
} }


Expand Down Expand Up @@ -184,8 +188,21 @@ public <T> T query(String queryName, QueryResultMapper<T> mapper, QueryContext q
.rowOffset(queryContext.getOffset()); .rowOffset(queryContext.getOffset());
Object filter = paramBuilder.build(); Object filter = paramBuilder.build();
while (filter != null ) { while (filter != null ) {
// add filter if (filter instanceof ColumnFilter) {
builder.filter((ColumnFilter) filter); // add filter
builder.filter((ColumnFilter) filter);
} else if (filter instanceof AggregateColumnFilter) {
// add aggregate function
builder.column(((AggregateColumnFilter) filter).getColumnId(), ((AggregateColumnFilter) filter).getType(), ((AggregateColumnFilter) filter).getColumnId());
} else if (filter instanceof GroupColumnFilter) {
// add group function
builder.group(((GroupColumnFilter) filter).getColumnId(), ((GroupColumnFilter) filter).getNewColumnId());
} else if (filter instanceof ExtraColumnFilter) {
// add extra column
builder.column(((ExtraColumnFilter) filter).getColumnId(), ((ExtraColumnFilter) filter).getNewColumnId());
} else {
logger.warn("Unsupported filter '{}' generated by '{}'", filter, paramBuilder);
}
// call builder again in case more parameters are available // call builder again in case more parameters are available
filter = paramBuilder.build(); filter = paramBuilder.build();
} }
Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.jbpm.kie.services.impl.query; package org.jbpm.kie.services.impl.query;


import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


import org.jbpm.services.api.query.model.QueryDefinition; import org.jbpm.services.api.query.model.QueryDefinition;


Expand All @@ -30,6 +32,8 @@ public class SqlQueryDefinition implements QueryDefinition, Serializable {
private String expression; private String expression;


private Target target = Target.CUSTOM; private Target target = Target.CUSTOM;

private Map<String, String> columnsMapping = new HashMap<String, String>();


public SqlQueryDefinition(String name, String source) { public SqlQueryDefinition(String name, String source) {
this.name = name; this.name = name;
Expand Down Expand Up @@ -93,4 +97,12 @@ public String toString() {
"{ expression=" + expression + "}]"; "{ expression=" + expression + "}]";
} }


public Map<String, String> getColumnsMapping() {
return columnsMapping;
}

public void setColumnsMapping(Map<String, String> columnsMapping) {
this.columnsMapping = columnsMapping;
}

} }

0 comments on commit b0aa884

Please sign in to comment.