| /** |
| * |
| * Copyright (c) 2011, 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 v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| package org.eclipse.osbp.xtext.cubedsl.validation; |
| |
| import com.google.common.base.Objects; |
| import java.util.HashSet; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.osbp.xtext.cubedsl.CubeDSLPackage; |
| 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.CubeHierarchy; |
| import org.eclipse.osbp.xtext.cubedsl.CubeLevel; |
| import org.eclipse.osbp.xtext.cubedsl.CubePackage; |
| import org.eclipse.osbp.xtext.cubedsl.validation.AbstractCubeDSLValidator; |
| import org.eclipse.xtext.validation.Check; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| |
| /** |
| * Custom validation rules. |
| * |
| * see http://www.eclipse.org/Xtext/documentation.html#validation |
| */ |
| @SuppressWarnings("all") |
| public class CubeDSLValidator extends AbstractCubeDSLValidator { |
| @Check |
| public void checkHierarchyLevelAtNoJoin(final CubeHierarchy hierarchy) { |
| boolean _and = false; |
| CubeDimensionEntity _cubeDimEntity = hierarchy.getCubeDimEntity(); |
| CubeDimensionEntityEntity _dimEntity = _cubeDimEntity.getDimEntity(); |
| boolean _equals = Objects.equal(_dimEntity, null); |
| if (!_equals) { |
| _and = false; |
| } else { |
| CubeDimensionEntity _cubeDimEntity_1 = hierarchy.getCubeDimEntity(); |
| EList<CubeLevel> _hierarchLevels = _cubeDimEntity_1.getHierarchLevels(); |
| int _size = _hierarchLevels.size(); |
| boolean _equals_1 = (_size == 0); |
| _and = _equals_1; |
| } |
| if (_and) { |
| this.error("Level is required on a non-join hierarchy!", CubeDSLPackage.Literals.CUBE_HIERARCHY__CUBE_DIM_ENTITY); |
| } |
| } |
| |
| @Check |
| public void checkTypeDimensionLevelType(final CubeDimension cubeDimension) { |
| boolean existLevelType = this.existLevelType(cubeDimension); |
| boolean _and = false; |
| if (!existLevelType) { |
| _and = false; |
| } else { |
| boolean _isTypeTime = cubeDimension.isTypeTime(); |
| boolean _not = (!_isTypeTime); |
| _and = _not; |
| } |
| if (_and) { |
| this.error("Dimension attribute \'type=\"TypeDimension\" required for Level attribute \'levelType\'!", CubeDSLPackage.Literals.CUBE_BASE__NAME); |
| } |
| } |
| |
| private boolean existLevelType(final CubeDimension cubeDimension) { |
| EList<CubeHierarchy> _hierarchies = cubeDimension.getHierarchies(); |
| for (final CubeHierarchy hierarchy : _hierarchies) { |
| CubeDimensionEntity _cubeDimEntity = hierarchy.getCubeDimEntity(); |
| EList<CubeLevel> _hierarchLevels = _cubeDimEntity.getHierarchLevels(); |
| for (final CubeLevel level : _hierarchLevels) { |
| boolean _isLevelType = level.isLevelType(); |
| if (_isLevelType) { |
| return true; |
| } |
| } |
| } |
| return false; |
| } |
| |
| @Check |
| public void checkDuplicateDimensionNames(final CubeDimension cubeDimension) { |
| EObject eObj = cubeDimension.eContainer(); |
| while ((!(eObj instanceof CubePackage))) { |
| EObject _eContainer = eObj.eContainer(); |
| eObj = _eContainer; |
| } |
| boolean _notEquals = (!Objects.equal(eObj, null)); |
| if (_notEquals) { |
| CubePackage cubePackage = ((CubePackage) eObj); |
| EList<CubeDimension> _dimensions = cubePackage.getDimensions(); |
| String _name = cubeDimension.getName(); |
| CubeDimension _findDuplicateDimensions = this.findDuplicateDimensions(_dimensions, _name); |
| boolean _notEquals_1 = (!Objects.equal(_findDuplicateDimensions, null)); |
| if (_notEquals_1) { |
| String _name_1 = cubeDimension.getName(); |
| String _concat = "Duplicate dimensionname \'".concat(_name_1); |
| String _concat_1 = _concat.concat("\'!"); |
| this.error(_concat_1, CubeDSLPackage.Literals.CUBE_BASE__NAME); |
| } |
| } |
| } |
| |
| private CubeDimension findDuplicateDimensions(final EList<CubeDimension> dims, final String cubeDimensionName) { |
| HashSet<String> tempSet = CollectionLiterals.<String>newHashSet(); |
| for (final CubeDimension dim : dims) { |
| boolean _and = false; |
| String _name = dim.getName(); |
| boolean _add = tempSet.add(_name); |
| boolean _not = (!_add); |
| if (!_not) { |
| _and = false; |
| } else { |
| String _name_1 = dim.getName(); |
| boolean _equals = _name_1.equals(cubeDimensionName); |
| _and = _equals; |
| } |
| if (_and) { |
| return dim; |
| } |
| } |
| return null; |
| } |
| } |