Skip to content

Commit

Permalink
Merge pull request #1282 from peterrinehart/PPP-4174-bugfix3
Browse files Browse the repository at this point in the history
[PPP-4174] Use classes from data-access when processing responses from
  • Loading branch information
ddiroma authored Oct 24, 2024
2 parents 3a8600b + c6246b4 commit 8bb57ad
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -93,4 +100,11 @@ public interface IColumn extends Serializable {
* @return
*/
public String getFormatMask();

/**
* Returns hidden for user flag
*
* @return
*/
public boolean isHiddenForUser();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,14 +29,17 @@
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 ];

/**
* Returns the id of the category
*/
@Override
public String getId() {
if ( this.id != null ) {
return this.id.replaceAll( "<", "&lt;" ).replaceAll( ">", "&gt;" );
}
return this.id;
}

Expand All @@ -45,7 +48,11 @@ public String getId() {
*/
@Override
public String getName() {
return this.name;
if ( this.name != null ) {
return this.name.replaceAll( "<", "&lt;" ).replaceAll( ">", "&gt;" );
} else {
return this.name;
}
}

/**
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,12 +24,10 @@
*
* @author jamesdixon
*/
public class ModelInfoComparator implements Comparator {
public class ModelInfoComparator implements Comparator<ModelInfo> {

@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() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> CLASS_LIST = new ArrayList<Class>( 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 ];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 ] + "\"" ) );
Expand All @@ -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 ] + "\")" ) );
Expand All @@ -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 ] + "\"))" ) );
Expand All @@ -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 ] + "\")" ) );
Expand All @@ -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 ] + "\")" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\"}";

Expand Down

0 comments on commit 8bb57ad

Please sign in to comment.