| /* |
| * |
| * 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 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.datamartdsl.validation |
| |
| import com.google.inject.Inject |
| import java.util.Set |
| import org.eclipse.osbp.xtext.basic.validation.IBasicValidatorDelegate |
| import org.eclipse.osbp.xtext.datamartdsl.AxisEnum |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartCube |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartCubeAxis |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDSLPackage |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDefinition |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartRole |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartTask |
| import org.eclipse.osbp.xtext.datamartdsl.util.DatamartAttributeUtil |
| import org.eclipse.xtext.validation.Check |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartSource |
| |
| /** |
| * Custom validation rules. |
| * |
| * see http://www.eclipse.org/Xtext/documentation.html#validation |
| */ |
| class DatamartDSLValidator extends AbstractDatamartDSLValidator { |
| |
| @Inject(optional=true) IBasicValidatorDelegate delegate |
| |
| @Check |
| def checkCommercialLicensed(DatamartDefinition datamart) { |
| if ((datamart.source instanceof DatamartTask)) { |
| if(delegate !== null && !delegate.validateCommercial("datamart", "net.osbee.bpm")) { |
| info('''BPM is needed and not yet licensed. License BPM at www.osbee.net''', datamart, null) |
| } |
| } |
| if ((datamart.source instanceof DatamartCube)) { |
| if(delegate !== null && !delegate.validateCommercial("datamart", "net.osbee.xtext.cube")) { |
| info('''Cube is needed and not yet licensed. License Cube at www.osbee.net''', datamart, null) |
| } |
| } |
| } |
| |
| @Check |
| def checkSecurityLicensed(DatamartRole role) { |
| if(delegate !== null && !delegate.validateCommercial("datamart", "net.osbee.organization.permissions")) { |
| info('''Authorization is needed and not yet licensed. License Authorization at www.osbee.net''', role, null) |
| } |
| } |
| |
| @Check |
| def checkForDuplicatedAttributeNamesOrAliases(DatamartAttribute attribute) { |
| var attributeNames = <String>newHashSet() |
| var eObj = attribute.eContainer |
| while ((eObj !== null) && !(eObj instanceof DatamartEntity)){ |
| eObj = eObj.eContainer |
| } |
| if (eObj !== null){ |
| (eObj as DatamartEntity).checkForDuplicatedAttributeNamesOrAliases(attributeNames) |
| } |
| } |
| |
| private def void checkForDuplicatedAttributeNamesOrAliases(DatamartEntity entity, Set<String> attributeNames) { |
| var error = false |
| for (attribute : entity.attributes) { |
| var added = attributeNames.add(DatamartAttributeUtil.getAliasedAttributeName(attribute)) |
| if (!added){ |
| error = true |
| var errorTxt = '''Duplicated attribute names or aliases are not allowed in the same datamart definition.''' |
| if (attribute.aliased){ |
| error(errorTxt, attribute, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE__ALIAS_NAME) |
| } else { |
| error(errorTxt, attribute, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE_BASE__ATTRIBUTE_REF) |
| } |
| } |
| } |
| if (!error){ |
| var eObj = entity.eContainer |
| while ((eObj !== null) && !(eObj instanceof DatamartEntity)){ |
| eObj = eObj.eContainer |
| } |
| if (eObj !== null){ |
| (eObj as DatamartEntity).checkForDuplicatedAttributeNamesOrAliases(attributeNames) |
| } |
| } |
| } |
| |
| /** |
| * Checks if both axis "rows" and "columns" are defined when a DatamartCube definition contains either the axis "pages", "chapters" "sections" or all 3 of them. |
| */ |
| @Check |
| def checkForRowsAndColumnsPresenceInCube(DatamartCube cube) { |
| var error = false |
| |
| var hasAxisColumns = cube.axisslicer.exists[it instanceof DatamartCubeAxis && (it as DatamartCubeAxis).axis.name == AxisEnum.COLUMNS] |
| var hasAxisRows = cube.axisslicer.exists[it instanceof DatamartCubeAxis && (it as DatamartCubeAxis).axis.name == AxisEnum.ROWS] |
| |
| var axisPages = cube.axisslicer.findFirst[it instanceof DatamartCubeAxis && (it as DatamartCubeAxis).axis.name == AxisEnum.PAGES] |
| var axisChapters = cube.axisslicer.findFirst[it instanceof DatamartCubeAxis && (it as DatamartCubeAxis).axis.name == AxisEnum.CHAPTERS] |
| var axisSections = cube.axisslicer.findFirst[it instanceof DatamartCubeAxis && (it as DatamartCubeAxis).axis.name == AxisEnum.SECTIONS] |
| |
| //Pages |
| if(axisPages!==null && !hasAxisColumns || axisPages!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' "pages" can't be used without setting up both "columns" and "rows".''' |
| error(errorTxt, axisPages, DatamartDSLPackage.Literals.DATAMART_CUBE_AXIS__AXIS) |
| } |
| //Chapters |
| if(axisChapters!==null && !hasAxisColumns || axisChapters!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' ''chapters'' can't be used without setting up both ''columns'' and ''rows''.''' |
| error(errorTxt, axisChapters, DatamartDSLPackage.Literals.DATAMART_CUBE_AXIS__AXIS) |
| } |
| //Sections |
| if(axisSections!==null && !hasAxisColumns || axisSections!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' ''sections'' can't be used without setting up both ''columns'' and ''rows''.''' |
| error(errorTxt, axisSections, DatamartDSLPackage.Literals.DATAMART_CUBE_AXIS__AXIS) |
| } |
| } |
| |
| /** |
| * Checks if both axis "rows" and "columns" are defined when a DatamartEntity definition contains either the axis "pages", "chapters" "sections" or all 3 of them. |
| */ |
| @Check |
| def checkForRowsAndColumnsPresenceInEntity(DatamartEntity entity) { |
| var error = false |
| |
| var hasAxisColumns = entity.attributes.exists[it instanceof DatamartAttribute && (it as DatamartAttribute).axis.name == AxisEnum.COLUMNS] |
| var hasAxisRows = entity.attributes.exists[it instanceof DatamartAttribute && (it as DatamartAttribute).axis.name == AxisEnum.ROWS] |
| |
| var axisPages = entity.attributes.findFirst[it instanceof DatamartAttribute && (it as DatamartAttribute).axis.name == AxisEnum.PAGES] |
| var axisChapters = entity.attributes.findFirst[it instanceof DatamartAttribute && (it as DatamartAttribute).axis.name == AxisEnum.CHAPTERS] |
| var axisSections = entity.attributes.findFirst[it instanceof DatamartAttribute && (it as DatamartAttribute).axis.name == AxisEnum.SECTIONS] |
| |
| //Pages |
| if(axisPages!==null && !hasAxisColumns || axisPages!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' ''pages'' can't be used without setting up both ''columns'' and ''rows''.''' |
| error(errorTxt, axisPages, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE__AXIS) |
| } |
| //Chapters |
| if(axisChapters!==null && !hasAxisColumns || axisChapters!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' ''chapters'' can't be used without setting up both ''columns'' and ''rows''.''' |
| error(errorTxt, axisChapters, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE__AXIS) |
| } |
| //Sections |
| if(axisSections!==null && !hasAxisColumns || axisSections!==null && !hasAxisRows){ |
| error = true |
| var errorTxt = ''' ''sections'' can't be used without setting up both ''columns'' and ''rows''.''' |
| error(errorTxt, axisSections, DatamartDSLPackage.Literals.DATAMART_ATTRIBUTE__AXIS) |
| } |
| } |
| |
| } |