diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/IColumn.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/IColumn.java index d214ae307..76f774b7f 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/IColumn.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/IColumn.java @@ -12,7 +12,7 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model; @@ -45,6 +45,13 @@ public interface IColumn extends Serializable { */ public String getName(); + /** + * Returns the description of the column + * + * @return + */ + public String getDescription(); + /** * Returns the category of the column * @@ -93,4 +100,11 @@ public interface IColumn extends Serializable { * @return */ public String getFormatMask(); + + /** + * Returns hidden for user flag + * + * @return + */ + public boolean isHiddenForUser(); } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/ICondition.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/ICondition.java index 4c0173cb6..283b0c36d 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/ICondition.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/ICondition.java @@ -12,7 +12,7 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model; @@ -81,9 +81,9 @@ public interface ICondition extends Serializable { * * @return true if value denotes parameter name rather than a literal value */ - // public boolean isParameterized(); + public boolean isParameterized(); - // public String getDefaultValue(); + // public String getDefaultValue(); - // public String getSelectedAggType(); + public String getSelectedAggType(); } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Category.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Category.java index 0e6018498..3faed95c8 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Category.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Category.java @@ -12,7 +12,7 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model.impl; @@ -29,7 +29,7 @@ public class Category implements ICategory, Serializable { private static final long serialVersionUID = -454688567483551796L; - private String id, name; + private String id, name, description; private Column[] columns = new Column[ 0 ]; /** @@ -37,6 +37,9 @@ public class Category implements ICategory, Serializable { */ @Override public String getId() { + if ( this.id != null ) { + return this.id.replaceAll( "<", "<" ).replaceAll( ">", ">" ); + } return this.id; } @@ -45,7 +48,11 @@ public String getId() { */ @Override public String getName() { - return this.name; + if ( this.name != null ) { + return this.name.replaceAll( "<", "<" ).replaceAll( ">", ">" ); + } else { + return this.name; + } } /** @@ -83,5 +90,12 @@ public void setColumns( Column[] columns ) { this.columns = columns; } + public void setDescription( String description ) { + this.description = description; + } + + public String getDescription() { + return description; + } } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Column.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Column.java index 1beb71aa0..da1b212b9 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Column.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Column.java @@ -27,15 +27,16 @@ public class Column implements IColumn { private static final long serialVersionUID = 3751750093446278893L; - private String id, name; + private String id, name, description; private String type; - private String[] aggTypes = new String[0]; + private String[] aggTypes = new String[ 0 ]; private String defaultAggType; private String selectedAggType; private String fieldType; private String category; private String getHorizontalAlignment; private String formatMask; + private boolean hiddenForUser; @Override public String getHorizontalAlignment() { @@ -127,5 +128,20 @@ public String getSelectedAggType() { return this.selectedAggType; } + public void setDescription( String description ) { + this.description = description; + } + + public String getDescription() { + return description; + } + public void setHiddenForUser( boolean hiddenForUser ) { + this.hiddenForUser = hiddenForUser; + } + + @Override + public boolean isHiddenForUser() { + return hiddenForUser; + } } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Condition.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Condition.java index a3d603c15..7efc7fa96 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Condition.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Condition.java @@ -12,11 +12,12 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model.impl; +import org.apache.commons.lang3.StringUtils; import org.pentaho.metadata.model.concept.types.DataType; import org.pentaho.metadata.query.model.CombinationType; import org.pentaho.platform.dataaccess.metadata.model.ICondition; @@ -30,9 +31,9 @@ public class Condition implements ICondition { private String operator = Operator.EQUAL.name(); private String[] value; private String comboType = CombinationType.AND.name(); - // private boolean parameterized; - // private String defaultValue; - // private String selectedAggType; + private boolean parameterized; + // private String defaultValue; + private String selectedAggType; public Condition() { @@ -75,36 +76,36 @@ public boolean validate() { } public String getCondition( String type ) { - return getCondition( type, column ); + return getCondition( type, isParameterized() ? value[0] : null ); } public String getCondition( String type, String paramName ) { String[] val = getValue().clone(); -/* - if(val == null && defaultValue != null) { - val = defaultValue; - } -*/ + /* + * if(val == null && defaultValue != null) { val = defaultValue; } + */ Operator theOperator = Operator.parse( getOperator() ); if ( type.equalsIgnoreCase( DataType.STRING.getName() ) && theOperator == Operator.EQUAL ) { theOperator = Operator.EXACTLY_MATCHES; } - if ( type.equalsIgnoreCase( DataType.STRING.getName() ) ) { + boolean enforceParameters = isParameterized() && paramName != null; + + if ( !enforceParameters && type.equalsIgnoreCase( DataType.STRING.getName() ) ) { for ( int idx = 0; idx < val.length; idx++ ) { - val[ idx ] = "\"" + val[ idx ] + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + val[ idx ] = "\"" + val[ idx ] + "\""; //$NON-NLS-1$ //$NON-NLS-2$ } } - boolean enforceParameters = paramName != null; - String columnName = "[" + getCategory() + "." + getColumn() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$; + + String columnName = + "[" + getCategory() + "." + getColumn() + ( StringUtils.isEmpty( selectedAggType ) ? "" : "." + selectedAggType ) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$; // Date is a special case where we craft a formula function. if ( type.equals( DataType.DATE.getName() ) ) { if ( enforceParameters ) { // Due to the fact that the value of a Date is a forumula function, the tokenizing of // the value needs to happen here instead of letting the Operator class handle it. for ( int idx = 0; idx < val.length; idx++ ) { - val[ idx ] = "DATEVALUE(" + "[param:" + getValue()[ idx ].replaceAll( "[\\{\\}]", "" ) + "]" - + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + val[ idx ] = "DATEVALUE(" + "[param:" + getValue()[idx].replaceAll( "[\\{\\}]", "" ) + "]" + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } return theOperator.formatCondition( columnName, paramName, val, false ); } else { @@ -116,31 +117,27 @@ public String getCondition( String type, String paramName ) { return theOperator.formatCondition( columnName, paramName, val, enforceParameters ); } - /* - public boolean isParameterized() { - return parameterized; - } + public boolean isParameterized() { + return parameterized; + } - public void setParameterized(boolean parameterized) { - this.parameterized = parameterized; - } - / - public void setDefaultValue(String val){ - this.defaultValue = val; - } + public void setParameterized( boolean parameterized ) { + this.parameterized = parameterized; + } - public String getDefaultValue(){ - return this.defaultValue; - } + /* + * public void setDefaultValue(String val){ this.defaultValue = val; } + * + * public String getDefaultValue(){ return this.defaultValue; } + */ + public void setSelectedAggType( String aggType ) { + this.selectedAggType = aggType; + } - public void setSelectedAggType(String aggType){ - this.selectedAggType = aggType; - } + public String getSelectedAggType() { + return this.selectedAggType; + } - public String getSelectedAggType(){ - return this.selectedAggType; - } - */ public String getCategory() { return category; } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/ModelInfoComparator.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/ModelInfoComparator.java index 10d3c2b5c..1d8a7518a 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/ModelInfoComparator.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/ModelInfoComparator.java @@ -12,7 +12,7 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model.impl; @@ -24,12 +24,10 @@ * * @author jamesdixon */ -public class ModelInfoComparator implements Comparator { +public class ModelInfoComparator implements Comparator { @Override - public int compare( Object obj1, Object obj2 ) { - ModelInfo model1 = (ModelInfo) obj1; - ModelInfo model2 = (ModelInfo) obj2; + public int compare( ModelInfo model1, ModelInfo model2 ) { return model1.getModelName().compareTo( model2.getModelName() ); } diff --git a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Query.java b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Query.java index 05af489f1..eb885b5ca 100644 --- a/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Query.java +++ b/core/src/main/java/org/pentaho/platform/dataaccess/metadata/model/impl/Query.java @@ -12,11 +12,14 @@ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. +* Copyright (c) 2002-2024 Hitachi Vantara.. All rights reserved. */ package org.pentaho.platform.dataaccess.metadata.model.impl; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; import org.pentaho.platform.dataaccess.metadata.model.IQuery; @@ -25,9 +28,11 @@ public class Query implements IQuery { private static final long serialVersionUID = 8616769258583080677L; - private Column[] columns = new Column[ 0 ]; + public static final List CLASS_LIST = new ArrayList( Arrays.asList( Query.class, Column.class, Order.class, Parameter.class, + Condition.class ) ); + private Column[] columns = new Column[0]; - private Condition[] conditions = new Condition[ 0 ]; + private Condition[] conditions = new Condition[0]; private Order[] orders = new Order[ 0 ]; diff --git a/core/src/test/java/org/pentaho/platform/dataaccess/ConditionTest.java b/core/src/test/java/org/pentaho/platform/dataaccess/ConditionTest.java index 48cc053c7..abd63b729 100644 --- a/core/src/test/java/org/pentaho/platform/dataaccess/ConditionTest.java +++ b/core/src/test/java/org/pentaho/platform/dataaccess/ConditionTest.java @@ -107,6 +107,7 @@ public void testSetAndGetValue() { public void testGetConditionWithParametersForAllDataTypes() { Operator[] operatorsType1Array = { Operator.GREATER_THAN, Operator.LESS_THAN, Operator.EQUAL, Operator.GREATOR_OR_EQUAL, Operator.LESS_OR_EQUAL }; + when( icondition.isParameterized() ).thenReturn( true ); for ( Operator operator : operatorsType1Array ) { @@ -196,6 +197,7 @@ public void testGetConditionWithParametersForAllDataTypes() { public void testGetConditionWithoutParametersForAllDataTypes() { Operator[] operatorsType1Array = { Operator.GREATER_THAN, Operator.LESS_THAN, Operator.EQUAL, Operator.GREATOR_OR_EQUAL, Operator.LESS_OR_EQUAL }; + when( icondition.isParameterized() ).thenReturn( false ); for ( Operator operator: operatorsType1Array ) { @@ -227,7 +229,7 @@ public void testGetConditionWithoutParametersForAllDataTypes() { if ( dataType.getName().equals( DataType.DATE.getName() ) ) { Assert.assertThat( icondition.getCondition( dataType.getName(), paramName ), - is( "[" + categoryName + "." + columnName + "] = \"DATEVALUE([param:" + values[ 0 ] + "])\"" ) ); + is( "[" + categoryName + "." + columnName + "] = \"DATEVALUE(\"" + values[ 0 ] + "\")\"" ) ); } else { Assert.assertThat( icondition.getCondition( dataType.getName(), null ), is( "[" + categoryName + "." + columnName + "] = \"" + values[ 0 ] + "\"" ) ); @@ -237,7 +239,7 @@ public void testGetConditionWithoutParametersForAllDataTypes() { if ( dataType.getName().equals( DataType.DATE.getName() ) ) { Assert.assertThat( icondition.getCondition( dataType.getName(), paramName ), - is( "CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[ 0 ] + "])\")" ) ); + is( "CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE(\"" + values[ 0 ] + "\")\")" ) ); } else { Assert.assertThat( icondition.getCondition( dataType.getName(), null ), is( "CONTAINS([" + categoryName + "." + columnName + "];\"" + values[ 0 ] + "\")" ) ); @@ -247,7 +249,7 @@ public void testGetConditionWithoutParametersForAllDataTypes() { if ( dataType.getName().equals( DataType.DATE.getName() ) ) { Assert.assertThat( icondition.getCondition( dataType.getName(), paramName ), - is( "NOT(CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[ 0 ] + "])\"))" ) ); + is( "NOT(CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE(\"" + values[ 0 ] + "\")\"))" ) ); } else { Assert.assertThat( icondition.getCondition( dataType.getName(), null ), is( "NOT(CONTAINS([" + categoryName + "." + columnName + "];\"" + values[ 0 ] + "\"))" ) ); @@ -257,7 +259,7 @@ public void testGetConditionWithoutParametersForAllDataTypes() { if ( dataType.getName().equals( DataType.DATE.getName() ) ) { Assert.assertThat( icondition.getCondition( dataType.getName(), paramName ), - is( "BEGINSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[ 0 ] + "])\")" ) ); + is( "BEGINSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE(\"" + values[ 0 ] + "\")\")" ) ); } else { Assert.assertThat( icondition.getCondition( dataType.getName(), null ), is( "BEGINSWITH([" + categoryName + "." + columnName + "];\"" + values[ 0 ] + "\")" ) ); @@ -267,7 +269,7 @@ public void testGetConditionWithoutParametersForAllDataTypes() { if ( dataType.getName().equals( DataType.DATE.getName() ) ) { Assert.assertThat( icondition.getCondition( dataType.getName(), paramName ), - is( "ENDSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[ 0 ] + "])\")" ) ); + is( "ENDSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE(\"" + values[ 0 ] + "\")\")" ) ); } else { Assert.assertThat( icondition.getCondition( dataType.getName(), null ), is( "ENDSWITH([" + categoryName + "." + columnName + "];\"" + values[ 0 ] + "\")" ) ); diff --git a/core/src/test/java/org/pentaho/platform/dataaccess/metadata/service/MetadataServiceTest.java b/core/src/test/java/org/pentaho/platform/dataaccess/metadata/service/MetadataServiceTest.java index 97eb0ae5b..d048fec42 100644 --- a/core/src/test/java/org/pentaho/platform/dataaccess/metadata/service/MetadataServiceTest.java +++ b/core/src/test/java/org/pentaho/platform/dataaccess/metadata/service/MetadataServiceTest.java @@ -219,7 +219,7 @@ public void testLoadModel() { public void testLoadModelJson() { final String expectedModelJson = "{\"categories\":[{\"class\":\"org.pentaho.platform.dataaccess.metadata.model.impl" - + ".Category\",\"columns\":[],\"id\":\"" + CATEGORY_ID + "\",\"name\":null}],\"class\":\"org.pentaho.platform" + + ".Category\",\"columns\":[],\"description\":null,\"id\":\"" + CATEGORY_ID + "\",\"name\":null}],\"class\":\"org.pentaho.platform" + ".dataaccess.metadata.model.impl.Model\",\"description\":null,\"domainId\":\"" + DOMAIN_ID + "\",\"id\":\"" + LOGICAL_MODEL_ID + "\",\"name\":\"" + LOGICAL_MODEL_NAME + "\"}";