| /** |
| * Copyright (c) 2013, 2016 - Loetz GmbH&Co.KG, 69115 Heidelberg, Germany |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.xtext.datamartdsl.scoping; |
| |
| import com.google.common.base.Objects; |
| import com.google.common.base.Predicate; |
| import com.google.common.collect.Iterables; |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.function.Consumer; |
| import javax.inject.Inject; |
| import org.eclipse.emf.common.util.BasicEList; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.common.util.URI; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EReference; |
| import org.eclipse.emf.ecore.InternalEObject; |
| import org.eclipse.osbp.dsl.common.xtext.extensions.ModelExtensions; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntity; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityFeature; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityReference; |
| import org.eclipse.osbp.xtext.cubedsl.CubeDimension; |
| import org.eclipse.osbp.xtext.cubedsl.CubeDimensionEntity; |
| import org.eclipse.osbp.xtext.cubedsl.CubeDimensionEntityEntity; |
| import org.eclipse.osbp.xtext.cubedsl.CubeDimensionUsage; |
| import org.eclipse.osbp.xtext.cubedsl.CubeHierarchy; |
| import org.eclipse.osbp.xtext.cubedsl.CubeLevel; |
| import org.eclipse.osbp.xtext.cubedsl.CubeMeasure; |
| import org.eclipse.osbp.xtext.cubedsl.CubeType; |
| import org.eclipse.osbp.xtext.cubedsl.CubeTypeEntity; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartCube; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDSLPackage; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDefineDerivedMeasure; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDefinition; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartHierarchy; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartMember; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartNavigation; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartOwner; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartReference; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartSource; |
| import org.eclipse.osbp.xtext.datamartdsl.scoping.AbstractDatamartDSLScopeProvider; |
| import org.eclipse.xtext.resource.IEObjectDescription; |
| import org.eclipse.xtext.scoping.IScope; |
| import org.eclipse.xtext.scoping.Scopes; |
| import org.eclipse.xtext.scoping.impl.FilteringScope; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| import org.eclipse.xtext.xbase.lib.Extension; |
| |
| /** |
| * This class contains custom scoping description. |
| * |
| * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping |
| * on how and when to use it |
| */ |
| @SuppressWarnings("restriction") |
| public class DatamartDSLScopeProvider extends AbstractDatamartDSLScopeProvider { |
| @Inject |
| @Extension |
| private ModelExtensions _modelExtensions; |
| |
| @Override |
| public IScope getScope(final EObject context, final EReference reference) { |
| boolean _equals = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_HIERARCHY__HIERARCHY_REF); |
| if (_equals) { |
| return this.getDatamartHierarchy_hierarchyRef(context); |
| } else { |
| boolean _equals_1 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_MEASURE__MEASURE_REF); |
| if (_equals_1) { |
| return this.getDatamartMeasure_measureRef(context); |
| } else { |
| boolean _equals_2 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_DERIVED_MEASURE__DERIVED_REF); |
| if (_equals_2) { |
| return this.getDatamartDerivedMeasure_derivedRef(context); |
| } else { |
| boolean _equals_3 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_HIERARCHY__LEVEL_REF); |
| if (_equals_3) { |
| return this.getDatamartHierarchy_levelRef(context); |
| } else { |
| boolean _equals_4 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_HIERARCHY__EXCEPT_REF); |
| if (_equals_4) { |
| return this.getDatamartHierarchy_levelRef(context); |
| } else { |
| boolean _equals_5 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_HIERARCHY__ORDER_REF); |
| if (_equals_5) { |
| return this.getDatamartMeasure_measureRef(context); |
| } else { |
| boolean _equals_6 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE_BASE__ATTRIBUTE_REF); |
| if (_equals_6) { |
| return this.getDatamartAttribute_attributeRef(context); |
| } else { |
| boolean _equals_7 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_REFERENCE_BASE__REFERENCE_REF); |
| if (_equals_7) { |
| return this.getDatamartAttribute_referenceRef(context); |
| } else { |
| boolean _equals_8 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_ORDER__ORDER_BY); |
| if (_equals_8) { |
| return this.getDatamartAttribute_attributeRef(context); |
| } else { |
| boolean _equals_9 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_REFERENCE__REF); |
| if (_equals_9) { |
| return this.getDatamartEntity_datamartReferenceRef(context, reference); |
| } else { |
| boolean _equals_10 = Objects.equal(reference, DatamartDSLPackage.Literals.DATAMART_ENTITY__ENTITY_REF); |
| if (_equals_10) { |
| return this.getDatamartEntity_datamartEntityRef(context, reference); |
| } else { |
| final IScope scope = super.getScope(context, reference); |
| return scope; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| public IScope getDatamartEntity_filterEntityRef(final EObject context, final EReference reference) { |
| final IScope scope = super.getScope(context, reference); |
| final Predicate<IEObjectDescription> _function = (IEObjectDescription it) -> { |
| final EObject entityProxy = it.getEObjectOrProxy(); |
| LEntity entity = null; |
| boolean _eIsProxy = entityProxy.eIsProxy(); |
| if (_eIsProxy) { |
| final URI uri = ((InternalEObject) entityProxy).eProxyURI(); |
| EObject _eObject = context.eResource().getResourceSet().getEObject(uri, true); |
| entity = ((LEntity) _eObject); |
| } else { |
| entity = ((LEntity) entityProxy); |
| } |
| boolean inheritedClass = false; |
| if ((entity != null)) { |
| if (((entity.getSuperType() != null) && (!entity.getSuperType().isMappedSuperclass()))) { |
| inheritedClass = true; |
| } |
| if (((!inheritedClass) && (!entity.isMappedSuperclass()))) { |
| return true; |
| } |
| } |
| return false; |
| }; |
| return new FilteringScope(scope, _function); |
| } |
| |
| public void iterateEntity(final DatamartEntity entity, final ArrayList<EObject> result) { |
| EList<DatamartAttribute> _attributes = entity.getAttributes(); |
| for (final DatamartAttribute prop : _attributes) { |
| result.add(prop.getAttributeRef()); |
| } |
| EList<DatamartNavigation> _navigations = entity.getNavigations(); |
| for (final DatamartNavigation navigation : _navigations) { |
| boolean _matched = false; |
| if (navigation instanceof DatamartMember) { |
| _matched=true; |
| this.iterateEntity(((DatamartMember) navigation).getDatamartEntity(), result); |
| } |
| if (!_matched) { |
| if (navigation instanceof DatamartOwner) { |
| _matched=true; |
| this.iterateEntity(((DatamartOwner) navigation).getDatamartEntity(), result); |
| } |
| } |
| } |
| } |
| |
| /** |
| * @param context |
| * @return LEntity |
| */ |
| public LEntity getDatamartEntity(final EObject context) { |
| EObject eObj = context.eContainer(); |
| while (((eObj != null) && (!(eObj instanceof DatamartEntity)))) { |
| eObj = eObj.eContainer(); |
| } |
| if ((eObj != null)) { |
| return ((DatamartEntity) eObj).getEntityRef(); |
| } else { |
| return null; |
| } |
| } |
| |
| /** |
| * @param context |
| * @return |
| */ |
| public IScope getDatamartAttribute_attributeRef(final EObject context) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| LEntity entity = this.getDatamartEntity(context); |
| if ((entity != null)) { |
| List<LEntityAttribute> _allAttributes = entity.getAllAttributes(); |
| for (final LEntityAttribute attr : _allAttributes) { |
| if (((attr.getName() != null) && (!(attr.isId() || attr.isUuid())))) { |
| result.add(attr); |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| /** |
| * @param context |
| * @return |
| */ |
| public IScope getDatamartAttribute_referenceRef(final EObject context) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| LEntity entity = this.getDatamartEntity(context); |
| if ((entity != null)) { |
| List<LEntityReference> _allReferences = entity.getAllReferences(); |
| for (final LEntityReference ref : _allReferences) { |
| result.add(ref); |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public IScope getDatamartEntity_datamartReferenceRef(final EObject context, final EReference reference) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObj = context.eContainer(); |
| while ((!(eObj instanceof DatamartEntity))) { |
| { |
| eObj = eObj.eContainer(); |
| if ((eObj == null)) { |
| return Scopes.scopeFor(result); |
| } |
| } |
| } |
| if ((eObj instanceof DatamartEntity)) { |
| List<LEntityReference> _allReferences = ((DatamartEntity) eObj).getEntityRef().getAllReferences(); |
| for (final LEntityReference ref : _allReferences) { |
| EObject _eContainer = ((DatamartReference) context).eContainer(); |
| if ((_eContainer instanceof DatamartOwner)) { |
| boolean _isToMany = this._modelExtensions.isToMany(((LEntityFeature) ref)); |
| boolean _not = (!_isToMany); |
| if (_not) { |
| result.add(ref); |
| } |
| } else { |
| boolean _isToMany_1 = this._modelExtensions.isToMany(((LEntityFeature) ref)); |
| if (_isToMany_1) { |
| result.add(ref); |
| } |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public IScope getDatamartEntity_datamartEntityRef(final EObject context, final EReference reference) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObj = context.eContainer(); |
| while ((!(eObj instanceof DatamartEntity))) { |
| { |
| eObj = eObj.eContainer(); |
| if ((eObj == null)) { |
| return super.getScope(context, reference); |
| } |
| } |
| } |
| if ((eObj instanceof DatamartEntity)) { |
| List<LEntityReference> _allReferences = ((DatamartEntity) eObj).getEntityRef().getAllReferences(); |
| for (final LEntityReference ref : _allReferences) { |
| EObject _eContainer = ((DatamartEntity) context).eContainer(); |
| if ((_eContainer instanceof DatamartOwner)) { |
| boolean _isToMany = this._modelExtensions.isToMany(((LEntityFeature) ref)); |
| boolean _not = (!_isToMany); |
| if (_not) { |
| result.add(ref.getType()); |
| } |
| } else { |
| boolean _isToMany_1 = this._modelExtensions.isToMany(((LEntityFeature) ref)); |
| if (_isToMany_1) { |
| result.add(ref.getType()); |
| } |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public IScope getDatamartHierarchy_hierarchyRef(final EObject context) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObj = context.eContainer(); |
| while ((!(eObj instanceof DatamartDefinition))) { |
| eObj = eObj.eContainer(); |
| } |
| if ((eObj != null)) { |
| if ((eObj instanceof DatamartDefinition)) { |
| DatamartSource _source = ((DatamartDefinition) eObj).getSource(); |
| boolean _tripleNotEquals = (_source != null); |
| if (_tripleNotEquals) { |
| DatamartSource datamartSource = ((DatamartDefinition)eObj).getSource(); |
| if ((datamartSource instanceof DatamartCube)) { |
| CubeType _cubeRef = ((DatamartCube)datamartSource).getCubeRef(); |
| boolean _tripleNotEquals_1 = (_cubeRef != null); |
| if (_tripleNotEquals_1) { |
| CubeType cube = ((DatamartCube)datamartSource).getCubeRef(); |
| if ((cube != null)) { |
| CubeTypeEntity _cubeTypeEntity = cube.getCubeTypeEntity(); |
| boolean _tripleNotEquals_2 = (_cubeTypeEntity != null); |
| if (_tripleNotEquals_2) { |
| BasicEList<CubeHierarchy> hierList = new BasicEList<CubeHierarchy>(); |
| EList<CubeDimensionUsage> _dimensionUsages = cube.getCubeTypeEntity().getDimensionUsages(); |
| for (final CubeDimensionUsage ccCubeDimensionUsage : _dimensionUsages) { |
| hierList.addAll(ccCubeDimensionUsage.getSourceValue().getHierarchies()); |
| } |
| result = this.getHierarchyList(hierList, result); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public IScope getDatamartHierarchy_levelRef(final EObject eObj) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObjLocal = eObj; |
| while ((!(eObjLocal instanceof DatamartHierarchy))) { |
| eObjLocal = eObjLocal.eContainer(); |
| } |
| if ((eObjLocal != null)) { |
| if ((eObjLocal instanceof DatamartHierarchy)) { |
| CubeHierarchy hierarchy = ((DatamartHierarchy)eObjLocal).getHierarchyRef(); |
| if ((hierarchy != null)) { |
| if ((hierarchy instanceof CubeHierarchy)) { |
| CubeDimensionEntity entity = hierarchy.getCubeDimEntity(); |
| if ((entity != null)) { |
| EList<CubeLevel> _hierarchLevels = entity.getHierarchLevels(); |
| for (final CubeLevel ccCubeLevel : _hierarchLevels) { |
| String _name = ccCubeLevel.getName(); |
| boolean _tripleNotEquals = (_name != null); |
| if (_tripleNotEquals) { |
| result.add(ccCubeLevel); |
| } |
| } |
| CubeDimensionEntityEntity _dimEntity = entity.getDimEntity(); |
| boolean _tripleNotEquals_1 = (_dimEntity != null); |
| if (_tripleNotEquals_1) { |
| this.recurseLevels(entity.getDimEntity(), result); |
| } |
| } |
| } |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public void recurseLevels(final CubeDimensionEntityEntity dimEntity, final ArrayList<EObject> result) { |
| if ((dimEntity != null)) { |
| EList<CubeLevel> _hierarchLevels = dimEntity.getHierarchLevels(); |
| for (final CubeLevel ccCubeLevel : _hierarchLevels) { |
| String _name = ccCubeLevel.getName(); |
| boolean _tripleNotEquals = (_name != null); |
| if (_tripleNotEquals) { |
| result.add(ccCubeLevel); |
| } |
| } |
| this.recurseLevels(dimEntity.getDimEntity(), result); |
| } |
| } |
| |
| public IScope getDatamartMeasure_measureRef(final EObject eObj) { |
| ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObjLocal = eObj.eContainer(); |
| while ((!(eObjLocal instanceof DatamartDefinition))) { |
| eObjLocal = eObjLocal.eContainer(); |
| } |
| if ((eObjLocal != null)) { |
| if ((eObjLocal instanceof DatamartDefinition)) { |
| DatamartSource _source = ((DatamartDefinition)eObjLocal).getSource(); |
| boolean _tripleNotEquals = (_source != null); |
| if (_tripleNotEquals) { |
| DatamartSource datamartSource = ((DatamartDefinition)eObjLocal).getSource(); |
| if ((datamartSource instanceof DatamartCube)) { |
| CubeType _cubeRef = ((DatamartCube)datamartSource).getCubeRef(); |
| boolean _tripleNotEquals_1 = (_cubeRef != null); |
| if (_tripleNotEquals_1) { |
| CubeType cube = ((DatamartCube)datamartSource).getCubeRef(); |
| if ((cube != null)) { |
| if ((cube instanceof CubeType)) { |
| CubeTypeEntity _cubeTypeEntity = cube.getCubeTypeEntity(); |
| boolean _tripleNotEquals_2 = (_cubeTypeEntity != null); |
| if (_tripleNotEquals_2) { |
| EList<CubeMeasure> _measures = cube.getCubeTypeEntity().getMeasures(); |
| for (final CubeMeasure ccCubeMeasure : _measures) { |
| String _name = ccCubeMeasure.getName(); |
| boolean _tripleNotEquals_3 = (_name != null); |
| if (_tripleNotEquals_3) { |
| result.add(ccCubeMeasure); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public IScope getDatamartDerivedMeasure_derivedRef(final EObject eObj) { |
| final ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList(); |
| EObject eObjLocal = eObj.eContainer(); |
| while ((!(eObjLocal instanceof DatamartCube))) { |
| EObject _eContainer = null; |
| if (eObjLocal!=null) { |
| _eContainer=eObjLocal.eContainer(); |
| } |
| eObjLocal = _eContainer; |
| } |
| if ((eObjLocal != null)) { |
| final DatamartCube cube = ((DatamartCube) eObjLocal); |
| final Consumer<DatamartDefineDerivedMeasure> _function = (DatamartDefineDerivedMeasure it) -> { |
| result.add(it); |
| }; |
| Iterables.<DatamartDefineDerivedMeasure>filter(cube.getAxisslicer(), DatamartDefineDerivedMeasure.class).forEach(_function); |
| } |
| return Scopes.scopeFor(result); |
| } |
| |
| public ArrayList<EObject> getHierarchyList(final EList<CubeHierarchy> hierList, final ArrayList<EObject> result) { |
| for (final CubeHierarchy ccCubeHierarchy : hierList) { |
| { |
| String name = ccCubeHierarchy.getName(); |
| if (((name == null) || (name.length() == 0))) { |
| EObject eObj = ccCubeHierarchy.eContainer(); |
| while ((!(eObj instanceof CubeDimension))) { |
| eObj = eObj.eContainer(); |
| } |
| name = ((CubeDimension) eObj).getName(); |
| ccCubeHierarchy.setName(name); |
| } |
| result.add(ccCubeHierarchy); |
| } |
| } |
| return result; |
| } |
| } |