Commit b3606946 authored by Giulio Gavardi's avatar Giulio Gavardi
Browse files

functions

parent 91239cea
/*
* Knowage, Open Source Business Intelligence suite
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
*
*
* Knowage is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
......@@ -11,7 +11,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -48,6 +48,7 @@ import it.eng.qbe.model.structure.builder.IModelStructureBuilder;
import it.eng.qbe.model.structure.builder.jpa.JPAModelStructureBuilder;
import it.eng.qbe.query.Filter;
import it.eng.qbe.query.filters.ProfileAttributesModelAccessModality;
import it.eng.qbe.utility.ProfileDialectThreadLocal;
import it.eng.spagobi.commons.bo.UserProfile;
import it.eng.spagobi.tools.datasource.bo.IDataSource;
import it.eng.spagobi.utilities.assertion.Assert;
......@@ -74,8 +75,7 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
if (configuration instanceof FileDataSourceConfiguration) {
this.configuration = configuration;
} else if (configuration instanceof CompositeDataSourceConfiguration) {
IDataSourceConfiguration subConf = ((CompositeDataSourceConfiguration) configuration).getSubConfigurations()
.get(0);
IDataSourceConfiguration subConf = ((CompositeDataSourceConfiguration) configuration).getSubConfigurations().get(0);
if (subConf instanceof FileDataSourceConfiguration) {
this.configuration = subConf;
this.configuration.loadDataSourceProperties().putAll(configuration.loadDataSourceProperties());
......@@ -99,9 +99,7 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
/*
* (non-Javadoc)
*
* @see
* it.eng.qbe.datasource.IHibernateDataSource#getSessionFactory(java.lang
* .String)
* @see it.eng.qbe.datasource.IHibernateDataSource#getSessionFactory(java.lang .String)
*/
@Override
public EntityManagerFactory getEntityManagerFactory(String dmName) {
......@@ -169,8 +167,7 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
IDataSource dataSource = (IDataSource) configuration.loadDataSourceProperties().get("datasource");
// FOR SPAGOBIMETA
if (dataSource == null) {
ConnectionDescriptor connectionDescriptor = (ConnectionDescriptor) configuration.loadDataSourceProperties()
.get("connection");
ConnectionDescriptor connectionDescriptor = (ConnectionDescriptor) configuration.loadDataSourceProperties().get("connection");
if (connectionDescriptor != null) {
dataSource = connectionDescriptor.getDataSource();
}
......@@ -189,12 +186,11 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
Map<String, List<String>> fieldsFilteredByRole = getFieldsFilteredByRole();
List<Filter> filtersOnProfileAttributes = getFiltersOnProfileAttributes();
Map<String,String> filtersConditionsOnProfileAttributes = getFiltersConditionsOnProfileAttribute();
Map<String, String> filtersConditionsOnProfileAttributes = getFiltersConditionsOnProfileAttribute();
if (!filtersOnProfileAttributes.isEmpty() || !fieldsFilteredByRole.isEmpty()) {
logger.debug(
"One or more profile attributes filters were found therefore profile attributes model access modality will be activated.");
this.setDataMartModelAccessModality(new ProfileAttributesModelAccessModality(filtersOnProfileAttributes,
fieldsFilteredByRole, profile, filtersConditionsOnProfileAttributes));
logger.debug("One or more profile attributes filters were found therefore profile attributes model access modality will be activated.");
this.setDataMartModelAccessModality(new ProfileAttributesModelAccessModality(filtersOnProfileAttributes, fieldsFilteredByRole, profile,
filtersConditionsOnProfileAttributes));
}
}
return dataMartModelStructure;
......@@ -237,8 +233,7 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
IModelField field = fieldsIt.next();
String attributeName = (String) field.getProperty("attribute");
if (attributeName != null && !attributeName.trim().equals("")) {
logger.debug("Found profile attribute filter on field " + field.getUniqueName()
+ ": profile attribute is " + attributeName);
logger.debug("Found profile attribute filter on field " + field.getUniqueName() + ": profile attribute is " + attributeName);
// Filter filter = new Filter(entity.getUniqueName(), "F{" +
// field.getName() + "} = {" + attributeName + "}");
List<String> values = new ArrayList<String>();
......@@ -252,18 +247,18 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
}
return toReturn;
}
private Map<String, String> getFiltersConditionsOnProfileAttribute() {
Map<String, String> toReturn = new HashMap<String, String>();
Iterator<String> it = dataMartModelStructure.getModelNames().iterator();
while (it.hasNext()) {
List<IModelEntity> list = dataMartModelStructure.getRootEntities(it.next());
Map<String,String> filterconditions = getFiltersConditionsOnProfileAttribute(list);
Map<String, String> filterconditions = getFiltersConditionsOnProfileAttribute(list);
toReturn.putAll(filterconditions);
}
return toReturn;
}
private Map<String, String> getFiltersConditionsOnProfileAttribute(List<IModelEntity> list) {
Map<String, String> toReturn = new HashMap<String, String>();
Iterator<IModelEntity> it = list.iterator();
......@@ -274,13 +269,13 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
while (fieldsIt.hasNext()) {
IModelField field = fieldsIt.next();
String attributeName = (String) field.getProperty("attribute");
//add filter condition to map only if there is a value for the property attribute (profile attribute)
// add filter condition to map only if there is a value for the property attribute (profile attribute)
if (attributeName != null && !attributeName.trim().equals("")) {
String filtercondition = (String) field.getProperty("filtercondition");
if (filtercondition != null && !filtercondition.trim().equals("")) {
toReturn.put(field.getUniqueName(), filtercondition);
logger.debug("Found profile attribute filter on field " + field.getUniqueName()
+ ": profile attribute is " + attributeName +" and is filter condition is "+ filtercondition);
logger.debug("Found profile attribute filter on field " + field.getUniqueName() + ": profile attribute is " + attributeName
+ " and is filter condition is " + filtercondition);
}
}
}
......@@ -324,6 +319,14 @@ public class JPADataSource extends AbstractDataSource implements IJpaDataSource
// to solve http://spagoworld.org/jira/browse/SPAGOBI-1934
if (dialect != null && dialect.contains("SQLServerDialect")) {
dialect = "org.hibernate.dialect.ExtendedSQLServerDialect";
} else if (dialect != null && dialect.contains("MySQL")) {
dialect = "org.hibernate.dialect.ExtendedMySQLDialect";
ProfileDialectThreadLocal.setDialect(dialect);
ProfileDialectThreadLocal.setUserProfile(userProfile);
} else if (dialect != null && dialect.contains("oracle")) {
dialect = "org.hibernate.dialect.ExtendedOracle10Dialect";
ProfileDialectThreadLocal.setUserProfile(userProfile);
ProfileDialectThreadLocal.setDialect(dialect);
}
// at the moment (04/2015) hibernate doesn't provide a dialect for hive
......
......@@ -339,4 +339,11 @@ public class FilteredModelStructure extends AbstractModelObject implements IMode
return wrappedModelStructure.getRootEntityDirectConnections(entity);
}
@Override
public IModelEntity getEntityByName(String notUniqueName) {
// TODO Auto-generated method stub
return null;
}
}
......@@ -174,6 +174,16 @@ public interface IModelStructure extends IModelObject {
*/
public IModelEntity getEntity(String entityUniqueName);
/**
* Gets the entity not by the unique name.
*
* @param Name
* the entity name
*
* @return the entity
*/
public IModelEntity getEntityByName(String notUniqueName);
// ----------------------------------
// Fields
// ----------------------------------
......
......@@ -315,6 +315,23 @@ public class ModelStructure extends AbstractModelObject implements IModelStructu
return entity;
}
/*
* (non-Javadoc)
*
* @see it.eng.qbe.model.structure.IModelStructure#getEntity(String entityUniqueName)
*/
@Override
public IModelEntity getEntityByName(String notUniqueName) {
IModelEntity toReturn = null;
for (Iterator iterator = entities.keySet().iterator(); iterator.hasNext() && toReturn == null;) {
String uniqueName = (String) iterator.next();
if (uniqueName.endsWith("::" + notUniqueName)) {
toReturn = entities.get(uniqueName);
}
}
return toReturn;
}
// Fields -----------------------------------------------------------
/*
......
/*
* Knowage, Open Source Business Intelligence suite
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
*
*
* Knowage is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
......@@ -11,15 +11,12 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.eng.qbe.query;
import java.util.List;
import it.eng.qbe.model.structure.ModelCalculatedField.Slot;
import it.eng.spagobi.tools.dataset.common.query.AggregationFunctions;
import it.eng.spagobi.tools.dataset.common.query.IAggregationFunction;
......@@ -27,29 +24,32 @@ import it.eng.spagobi.tools.dataset.common.query.IAggregationFunction;
* @author Andrea Gioia (andrea.gioia@eng.it)
*/
public class InLineCalculatedSelectField extends AbstractSelectField {
private String expression;
private String slots;
private String type;
private String nature;
// private Object initialValue;
// private Object initialValue;
private boolean groupByField;
private IAggregationFunction function;
private String orderType;
// private int resetType;
// private int incrementType;
public InLineCalculatedSelectField(String alias, String expression, String slots, String type, String nature, boolean included, boolean visible, boolean groupByField, String orderType, String function ) {
private String entity;
// private int resetType;
// private int incrementType;
public InLineCalculatedSelectField(String alias, String expression, String slots, String type, String nature, boolean included, boolean visible,
boolean groupByField, String orderType, String function, String entity) {
super(alias, ISelectField.CALCULATED_FIELD, included, visible);
this.expression = expression;
this.slots = slots;
this.type = type;
this.nature = nature;
this.groupByField = groupByField;
this.entity = entity;
setOrderType(orderType);
setFunction( AggregationFunctions.get(function) );
setFunction(AggregationFunctions.get(function));
}
public String getExpression() {
return expression;
}
......@@ -57,7 +57,7 @@ public class InLineCalculatedSelectField extends AbstractSelectField {
public void setExpression(String expression) {
this.expression = expression;
}
public String getSlots() {
return slots;
}
......@@ -66,59 +66,66 @@ public class InLineCalculatedSelectField extends AbstractSelectField {
this.slots = slots;
}
@Override
public String getType() {
return type;
}
@Override
public void setType(String type) {
this.type = type;
}
@Override
public String getNature() {
return nature;
}
@Override
public void setNature(String nature) {
this.nature = nature;
}
@Override
public ISelectField copy() {
return null;
}
@Override
public boolean isInLineCalculatedField() {
return true;
}
@Override
public boolean isGroupByField() {
return groupByField;
}
@Override
public void setGroupByField(boolean groupByField) {
this.groupByField = groupByField;
}
@Override
public boolean isOrderByField() {
return "ASC".equalsIgnoreCase( getOrderType() )
|| "DESC".equalsIgnoreCase( getOrderType() );
return "ASC".equalsIgnoreCase(getOrderType()) || "DESC".equalsIgnoreCase(getOrderType());
}
@Override
public boolean isAscendingOrder() {
return "ASC".equalsIgnoreCase( getOrderType() );
return "ASC".equalsIgnoreCase(getOrderType());
}
@Override
public String getOrderType() {
return orderType;
}
@Override
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public IAggregationFunction getFunction() {
return function;
}
......@@ -127,13 +134,22 @@ public class InLineCalculatedSelectField extends AbstractSelectField {
this.function = function;
}
@Override
public String getName() {
return getAlias();
}
@Override
public void setName(String alias) {
setAlias(alias);
}
public String getEntity() {
return entity;
}
public void setEntity(String entity) {
this.entity = entity;
}
}
......@@ -266,8 +266,8 @@ public class Query implements IQuery {
@Override
public void addSelectFiled(String fieldUniqueName, String function, String fieldAlias, boolean include, boolean visible, boolean groupByField,
String orderType, String pattern, String orderColumn) {
selectFields.add(new SimpleSelectField(fieldUniqueName, function, fieldAlias, include, visible, groupByField, orderType, pattern, null, null,
orderColumn));
selectFields
.add(new SimpleSelectField(fieldUniqueName, function, fieldAlias, include, visible, groupByField, orderType, pattern, null, null, orderColumn));
}
/**
......@@ -291,8 +291,9 @@ public class Query implements IQuery {
}
public void addInLineCalculatedFiled(String fieldAlias, String expression, String slots, String type, String nature, boolean included, boolean visible,
boolean groupByField, String orderType, String funct) {
selectFields.add(new InLineCalculatedSelectField(fieldAlias, expression, slots, type, nature, included, visible, groupByField, orderType, funct));
boolean groupByField, String orderType, String funct, String entity) {
selectFields
.add(new InLineCalculatedSelectField(fieldAlias, expression, slots, type, nature, included, visible, groupByField, orderType, funct, entity));
}
public WhereField addWhereField(String name, String description, boolean promptable, it.eng.qbe.query.WhereField.Operand leftOperand, String operator,
......@@ -315,8 +316,8 @@ public class Query implements IQuery {
String leftOperatorType, String[] leftOperatorDefaulttValues, String[] leftOperatorLastValues, String leftOperatorAlias, String operator,
String[] rightOperatorValues, String rightOperatorDescription, String rightOperatorType, String[] rightOperatorDefaulttValues,
String[] rightOperatorLastValues, String rightOperatorAlias, String booleanConnector) {
it.eng.qbe.query.WhereField.Operand leftOperand = new it.eng.qbe.query.WhereField.Operand(leftOperatorValues, leftOperatorDescription,
leftOperatorType, leftOperatorDefaulttValues, leftOperatorLastValues, leftOperatorAlias);
it.eng.qbe.query.WhereField.Operand leftOperand = new it.eng.qbe.query.WhereField.Operand(leftOperatorValues, leftOperatorDescription, leftOperatorType,
leftOperatorDefaulttValues, leftOperatorLastValues, leftOperatorAlias);
it.eng.qbe.query.WhereField.Operand rightOperand = new it.eng.qbe.query.WhereField.Operand(rightOperatorValues, rightOperatorDescription,
rightOperatorType, rightOperatorDefaulttValues, rightOperatorLastValues, rightOperatorAlias);
WhereField whereField = new WhereField(name, description, promptable, leftOperand, operator, rightOperand, booleanConnector);
......@@ -395,8 +396,8 @@ public class Query implements IQuery {
}
public void removeSelectField(int fieldIndex) {
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < selectFields.size(), "Index [" + fieldIndex + "] out of bound for select fields list (0 - "
+ selectFields.size() + ")");
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < selectFields.size(),
"Index [" + fieldIndex + "] out of bound for select fields list (0 - " + selectFields.size() + ")");
selectFields.remove(fieldIndex);
}
......@@ -410,20 +411,20 @@ public class Query implements IQuery {
}
public void removeWhereField(int fieldIndex) {
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < whereClause.size(), "Index [" + fieldIndex + "] out of bound for select fields list (0 - "
+ whereClause.size() + ")");
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < whereClause.size(),
"Index [" + fieldIndex + "] out of bound for select fields list (0 - " + whereClause.size() + ")");
whereClause.remove(fieldIndex);
}
public void removeHavingField(int fieldIndex) {
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < havingClause.size(), "Index [" + fieldIndex + "] out of bound for select fields list (0 - "
+ havingClause.size() + ")");
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < havingClause.size(),
"Index [" + fieldIndex + "] out of bound for select fields list (0 - " + havingClause.size() + ")");
havingClause.remove(fieldIndex);
}
public ISelectField getSelectFieldByIndex(int fieldIndex) {
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < selectFields.size(), "Index [" + fieldIndex + "] out of bound for select fields list (0 - "
+ selectFields.size() + ")");
Assert.assertTrue(fieldIndex >= 0 && fieldIndex < selectFields.size(),
"Index [" + fieldIndex + "] out of bound for select fields list (0 - " + selectFields.size() + ")");
return selectFields.get(fieldIndex);
}
......@@ -714,7 +715,8 @@ public class Query implements IQuery {
return true;
}
private void replaceFieldsIncalculatedFields(InLineCalculatedSelectField cf, Map<IModelField, Set<IQueryField>> modelFieldsInvolved, IDataSource dataSource) {
private void replaceFieldsIncalculatedFields(InLineCalculatedSelectField cf, Map<IModelField, Set<IQueryField>> modelFieldsInvolved,
IDataSource dataSource) {
IModelField modelField;
try {
......
......@@ -161,6 +161,7 @@ public class QueryJSONDeserializer implements IQueryDeserializer {
String nature;
String expression;
String slots;
String entity;
boolean visible;
boolean included;
......@@ -263,11 +264,13 @@ public class QueryJSONDeserializer implements IQueryDeserializer {
}
expression = fieldClaculationDescriptor.getString(QuerySerializationConstants.FIELD_EXPRESSION);
slots = fieldClaculationDescriptor.optString(QuerySerializationConstants.FIELD_SLOTS);
entity = fieldJSON.optString(QuerySerializationConstants.FIELD_ENTITY);
group = fieldJSON.getString(QuerySerializationConstants.FIELD_GROUP);
order = fieldJSON.getString(QuerySerializationConstants.FIELD_ORDER);
funct = fieldJSON.getString(QuerySerializationConstants.FIELD_AGGREGATION_FUNCTION);
query.addInLineCalculatedFiled(alias, expression, slots, type, nature, included, visible, group.equalsIgnoreCase("true"), order, funct);
query.addInLineCalculatedFiled(alias, expression, slots, type, nature, included, visible, group.equalsIgnoreCase("true"), order, funct,
entity);
} else {
Assert.assertUnreachable("Type [" + fieldType + "] of field [" + alias + "] is not valid");
}
......
/*
* Knowage, Open Source Business Intelligence suite
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
*
*
* Knowage is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
......@@ -11,12 +11,23 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.eng.qbe.query.serializer.json;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import it.eng.qbe.datasource.IDataSource;
import it.eng.qbe.model.properties.IModelProperties;
import it.eng.qbe.model.structure.IModelEntity;
......@@ -38,17 +49,6 @@ import it.eng.spagobi.commons.utilities.StringUtilities;
import it.eng.spagobi.utilities.assertion.Assert;
import it.eng.spagobi.utilities.json.JSONUtils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Andrea Gioia (andrea.gioia@eng.it)
*/
......@@ -299,11 +299,13 @@ public class QueryJSONSerializer implements IQuerySerializer {
fieldJSON.put(QuerySerializationConstants.FIELD_TYPE, ISelectField.IN_LINE_CALCULATED_FIELD);
JSONObject fieldCalculationDescriptor = new JSONObject();
fieldCalculationDescriptor.put(QuerySerializationConstants.FIELD_NAME, calculatedSelectField.getName());
fieldCalculationDescriptor.put(QuerySerializationConstants.FIELD_ALIAS, calculatedSelectField.getAlias());
fieldCalculationDescriptor.put(QuerySerializationConstants.FIELD_TYPE, calculatedSelectField.getType());
fieldCalculationDescriptor.put(QuerySerializationConstants.FIELD_EXPRESSION, calculatedSelectField.getExpression());
fieldJSON.put(QuerySerializationConstants.FIELD_ID, fieldCalculationDescriptor);
fieldJSON.put(QuerySerializationConstants.FIELD_LONG_DESCRIPTION, calculatedSelectField.getExpression());
fieldJSON.put(QuerySerializationConstants.FIELD_ENTITY, calculatedSelectField.getEntity());
if (calculatedSelectField.isGroupByField()) {
fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "true");
......@@ -365,8 +367,8 @@ public class QueryJSONSerializer implements IQuerySerializer {
}
if (datamartFields.get(alias) == null)
continue;
if ((!(datamartFields.get(alias)).equals(QuerySerializationConstants.FIELD_NATURE_MEASURE) && !(datamartFields.get(alias))
.equals(QuerySerializationConstants.FIELD_NATURE_MANDATORY_MEASURE))) {
if ((!(datamartFields.get(alias)).equals(QuerySerializationConstants.FIELD_NATURE_MEASURE)
&& !(datamartFields.get(alias)).equals(QuerySerializationConstants.FIELD_NATURE_MANDATORY_MEASURE))) {
return QuerySerializationConstants.FIELD_NATURE_ATTRIBUTE;
}
}
......@@ -433,7 +435,7 @@ public class QueryJSONSerializer implements IQuerySerializer {
}
/*
*
*
* Iterator it = query.getSelectFields().iterator(); while( it.hasNext() ) { SelectField selectField = (SelectField)it.next(); DataMartField datamartField =
* getDatamartModel().getDataMartModelStructure().getField(selectField.getUniqueName()); String label; label = datamartLabels.getLabel(datamartField); label
* = StringUtilities.isEmpty(label)? datamartField.getName(): label; }
......
/*
* Knowage, Open Source Business Intelligence suite
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
*
*
* Knowage is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
......@@ -11,13 +11,22 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.eng.qbe.statement;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;