catch up with branch development

Signed-off-by: Ralf Mollik <ramollik@compex-commerce.com>
diff --git a/org.eclipse.osbp.xtext.datamart.common/META-INF/MANIFEST.MF b/org.eclipse.osbp.xtext.datamart.common/META-INF/MANIFEST.MF
index f329bf3..f305119 100644
--- a/org.eclipse.osbp.xtext.datamart.common/META-INF/MANIFEST.MF
+++ b/org.eclipse.osbp.xtext.datamart.common/META-INF/MANIFEST.MF
@@ -37,6 +37,7 @@
  org.eclipse.osbp.ui.api.metadata;version="0.9.0",
  org.eclipse.osbp.ui.api.themes;version="0.9.0",
  org.eclipse.osbp.ui.api.user;version="0.9.0",
+ org.eclipse.osbp.ui.api.useraccess;version="0.9.0",
  org.eclipse.osbp.utils.entityhelper;version="0.9.0",
  org.eclipse.osbp.xtext.entitymock.common.filler;version="0.9.0",
  org.eclipse.osbp.xtext.i18n;version="0.9.0",
diff --git a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ACubeDatamart.java b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ACubeDatamart.java
index b16f4a4..5d6c7eb 100644
--- a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ACubeDatamart.java
+++ b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ACubeDatamart.java
@@ -15,8 +15,8 @@
 package org.eclipse.osbp.xtext.datamart.common;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.osbp.dsl.common.datatypes.IDto;
 import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCellSet;
@@ -28,7 +28,11 @@
 
 	public abstract DerivedCellSet getResults(final Class operativeDtoClass, final List<IDto> operativeDtos);
 	@Override
-	public final HashMap<Integer, ArrayList<String>> getAxisMap() {
+	public final Map<Integer, ArrayList<String>> getAxisMap() {
+		return null;
+	}
+	@Override
+	public final Map<String, String> getAliasMap() {
 		return null;
 	}
 }
diff --git a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ADatamart.java b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ADatamart.java
index 3dd6c6b..7b399e9 100644
--- a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ADatamart.java
+++ b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ADatamart.java
@@ -15,9 +15,9 @@
 package org.eclipse.osbp.xtext.datamart.common;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.osbp.preferences.EnumDatabaseVendor;
 import org.eclipse.osbp.preferences.ProductConfiguration;
@@ -46,23 +46,28 @@
 	 *
 	 * @return the axis map
 	 */
-	public abstract HashMap<Integer,ArrayList<String>> getAxisMap();
+	public abstract Map<Integer,ArrayList<String>> getAxisMap();
 	
 	
 	/* (non-Javadoc)
 	 * @see org.eclipse.osbp.ui.api.datamart.IDataMart#getIdMap()
 	 */
-	public abstract HashMap<String, EType> getIdMap();
+	public abstract Map<String, EType> getIdMap();
+	
+	/* (non-Javadoc)
+	 * @see org.eclipse.osbp.ui.api.datamart.IDataMart#getAliasMap()
+	 */
+	public abstract Map<String, String> getAliasMap();
 	
 	/* (non-Javadoc)
 	 * @see org.eclipse.osbp.ui.api.datamart.IDataMart#getTypesMap()
 	 */
-	public abstract HashMap<String, EType> getTypesMap();
+	public abstract Map<String, EType> getTypesMap();
 	
 	/* (non-Javadoc)
 	 * @see org.eclipse.osbp.ui.api.datamart.IDataMart#getTypesProp()
 	 */
-	public abstract HashMap<String, String> getTypesProp();
+	public abstract Map<String, String> getTypesProp();
 	
 	/**
 	 * Disconnect.
diff --git a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ATaskDatamart.java b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ATaskDatamart.java
index 669c006..62abe38 100644
--- a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ATaskDatamart.java
+++ b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/ATaskDatamart.java
@@ -16,14 +16,14 @@
  package org.eclipse.osbp.xtext.datamart.common;
 
 import java.sql.Connection;
-import java.util.ArrayList;
 import java.util.Map;
 
-import org.eclipse.osbp.bpm.api.IBPMTaskClient;
-import org.eclipse.osbp.ui.api.datamart.DatamartFilter;
-import org.eclipse.osbp.ui.api.user.IUser;
 import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCellSet;
 
 public abstract class ATaskDatamart extends ADatamart<Connection> {
 	public abstract DerivedCellSet getResults();
+	@Override
+	public final Map<String, String> getAliasMap() {
+		return null;
+	}
 }
diff --git a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/sql/SqlCellSet.java b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/sql/SqlCellSet.java
index 52b2b05..7bafd48 100644
--- a/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/sql/SqlCellSet.java
+++ b/org.eclipse.osbp.xtext.datamart.common/src/org/eclipse/osbp/xtext/datamart/common/sql/SqlCellSet.java
@@ -39,10 +39,15 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.eclipse.osbp.bpm.api.BPMTaskSummary;
 import org.eclipse.osbp.dsl.common.datatypes.IDto;
 import org.eclipse.osbp.ui.api.datamart.DatamartPrimary;
 import org.eclipse.osbp.ui.api.datamart.IDataMart.EType;
+import org.eclipse.osbp.ui.api.useraccess.AbstractAuthorization.Action;
+import org.eclipse.osbp.ui.api.useraccess.AbstractAuthorization.Group;
+import org.eclipse.osbp.ui.api.useraccess.IUserAccessService;
 import org.eclipse.osbp.xtext.datamart.common.DatamartDtoMapper;
 import org.olap4j.Cell;
 import org.olap4j.CellSet;
@@ -107,8 +112,9 @@
 	}};
 	
 	private OperativeDtoContainer operativeDtoContainer = null;
+	private IUserAccessService userAccessService;
 	
-	public SqlCellSet(List<BPMTaskSummary> tasks, HashMap<Integer,ArrayList<String>> axisMap) {
+	public SqlCellSet(List<BPMTaskSummary> tasks, Map<Integer,ArrayList<String>> axisMap) {
 		fCells = new ArrayList<>();
 		fAxes = new ArrayList<>();
 		sqlAxes = new ArrayList<>();
@@ -258,11 +264,11 @@
 		
 	}
 
-	private boolean isId(String columnName, HashMap<String, EType> idMap) {
+	private boolean isId(String columnName, Map<String, EType> idMap) {
 		return idMap.keySet().iterator().hasNext() && columnName.equals(idMap.keySet().iterator().next());
 	}
 	
-	private EType getType(String columnName, HashMap<String, EType> idMap) {
+	private EType getType(String columnName, Map<String, EType> idMap) {
 		if(idMap.keySet().iterator().hasNext()) {
 			return idMap.get(idMap.keySet().iterator().next());
 		}
@@ -270,7 +276,8 @@
 	}
 
 	
-	public SqlCellSet(ResultSet rs, HashMap<Integer,ArrayList<String>> axisMap, HashMap<String, EType> idMap, DatamartDtoMapper datamartDtoMapper, Class<?> operativeDtoClass, List<IDto> operativeDtos, List<DatamartPrimary<?>> primaryKeys) {
+	public SqlCellSet(ResultSet rs, Map<Integer,ArrayList<String>> axisMap, Map<String, EType> idMap,  Map<String, String> aliasMap, DatamartDtoMapper datamartDtoMapper, Class<?> operativeDtoClass, List<IDto> operativeDtos, List<DatamartPrimary<?>> primaryKeys, IUserAccessService userAccessService) {
+		this.userAccessService = userAccessService;
 		operativeDtoContainer = null;
 		fCells = new ArrayList<>();
 		fAxes = new ArrayList<>();
@@ -360,8 +367,26 @@
 								for (String columnLabel : axisMap.get(axisNumber)) {
 									try {
 										int columnIdx = rs.findColumn(columnLabel);
-							    		formattedValue = getFormattedValue(rs, columnIdx);
-							    		value = getCastedValue(rs, columnIdx);
+										formattedValue = "";
+										value = null;
+										if(aliasMap.containsKey(columnLabel)) {
+											
+											String colFQN=aliasMap.get(columnLabel);											
+											String entityFQNArray[] = colFQN.split("\\.");
+											String columnName=entityFQNArray[entityFQNArray.length-1];
+											String entityFQN=StringUtils.join(ArrayUtils.remove(entityFQNArray, entityFQNArray.length-1),".");
+											
+											boolean entityOk = userAccessService.isGranted(Group.ENTITY, Action.READABLE, entityFQN);
+											boolean attributeOk = !userAccessService.isVetoed(Group.ENTITY, Action.INVISIBLE, entityFQN, columnName); 
+											if (entityOk && attributeOk) {
+												formattedValue = getFormattedValue(rs, columnIdx);
+												value = getCastedValue(rs, columnIdx);
+											}
+										} else {
+											formattedValue = getFormattedValue(rs, columnIdx);
+											value = getCastedValue(rs, columnIdx);
+										}
+										
 										if(primaryMap.containsKey(columnLabel)) {
 											primaryMap.get(columnLabel).add(value);
 										}
@@ -377,10 +402,26 @@
 							}
 		    			}
 						else {
-					    	for (int idx=1; idx<=numColumns; idx++) {
-					    		String columnLabel = rs.getMetaData().getColumnLabel(idx);
-					    		formattedValue = getFormattedValue(rs, idx);
-					    		value = getCastedValue(rs, idx);
+					    	for (int columnIdx=1; columnIdx<=numColumns; columnIdx++) {
+					    		String columnLabel = rs.getMetaData().getColumnLabel(columnIdx);
+								formattedValue = "";
+								value = null;
+								if(aliasMap.containsKey(columnLabel)) {
+									
+									String colFQN=aliasMap.get(columnLabel);											
+									String entityFQNArray[] = colFQN.split("\\.");
+									String columnName=entityFQNArray[entityFQNArray.length-1];
+									String entityFQN=StringUtils.join(ArrayUtils.remove(entityFQNArray, entityFQNArray.length-1),".");
+									
+									if (userAccessService.isGranted(Group.ENTITY, Action.READABLE, entityFQN) &&
+										!userAccessService.isVetoed(Group.ENTITY, Action.INVISIBLE, entityFQN, aliasMap.get(columnName))) {
+										formattedValue = getFormattedValue(rs, columnIdx);
+										value = getCastedValue(rs, columnIdx);
+									}
+								} else {
+									formattedValue = getFormattedValue(rs, columnIdx);
+									value = getCastedValue(rs, columnIdx);
+								}
 								if(primaryMap.containsKey(columnLabel)) {
 									primaryMap.get(columnLabel).add(value);
 								}