Skip to content

Commit

Permalink
FIPS-11711/FIPS-11712 :: TableUsage#setTableName
Browse files Browse the repository at this point in the history
Change-Id: I0c90b3c9c985929e75174d3d0e4cbc24f9ac3c2b
  • Loading branch information
hookyAt authored and hd42 committed May 27, 2024
1 parent f5bcf4d commit 7a8a797
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public ITable<?> getTable(IProductComponent productComponent, Calendar effective
}

/**
* Returns the name of the table the given product component references for this table usage. If
* this table usage is changing over time (resides in the generation) the date is used to
* Returns the name of the table for the given product component that references a table usage.
* If this table usage is changing over time (resides in the generation) the date is used to
* retrieve the correct generation. If the date is <code>null</code> the latest generation is
* used. If the table usage is not changing over time the date will be ignored.
*
Expand Down Expand Up @@ -90,6 +90,36 @@ public String getTableName(IProductComponent productComponent, Calendar effectiv
return tableName;
}

/**
* Sets the name of the table for the given product component that references a table usage. If
* this table usage is changing over time (resides in the generation) the date is used to
* retrieve the correct generation. If the date is <code>null</code> the latest generation is
* used. If the table usage is not changing over time the date will be ignored.
*
*
* @param tableName The name of the table for this table usage in the product component
* @param productComponent The product component that holds the table instance
* @param effectiveDate the date to determine the product component generation. If
* <code>null</code> the latest generation is used. Is ignored if the table usage
* configuration is not changing over time.
*
* @since 24.7
*/
public void setTableName(String tableName, IProductComponent productComponent, Calendar effectiveDate) {
try {
String setterNameForTableName = "set" + getter.getName().substring(3) + "Name";
Method setterForName = getter.getDeclaringClass().getDeclaredMethod(setterNameForTableName, String.class);
setterForName.invoke(getRelevantProductObject(productComponent, effectiveDate, isChangingOverTime()),
tableName);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new IllegalArgumentException(
String.format("Could not set table name for table usage %s on product component %s.",
getName(), productComponent),
e);
}
}

private boolean isChangingOverTime() {
return IProductComponentGeneration.class.isAssignableFrom(getter.getDeclaringClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,36 @@ public void testGetTable3Name() {
assertThat(tableUsage.getTableName(product, effectiveDate), is("Foo"));
}

@Test
public void testSetTable1Name() {
Product product = new Product();
ProductCmptType productCmptType = IpsModel.getProductCmptType(product);
TableUsage tableUsage = productCmptType.getTableUsage("table1");
assertThat(tableUsage, is(notNullValue()));
tableUsage.setTableName("NotFoo", product, effectiveDate);
assertThat(product.getTable1Name(), is("NotFoo"));
}

@Test
public void testSetTable2Name() {
Product product = new Product();
ProductCmptType productCmptType = IpsModel.getProductCmptType(product);
TableUsage tableUsage = productCmptType.getTableUsage("table2");
assertThat(tableUsage, is(notNullValue()));
tableUsage.setTableName("NotBar", product, effectiveDate);
assertThat(product.getTable2Name(), is("NotBar"));
}

@Test
public void testSetTable3Name() {
ChildProduct product = new ChildProduct();
ProductCmptType productCmptType = IpsModel.getProductCmptType(product);
TableUsage tableUsage = productCmptType.getTableUsage("table3");
assertThat(tableUsage, is(notNullValue()));
tableUsage.setTableName("NotFoo", product, effectiveDate);
assertThat(product.getTable3Name(), is("NotFoo"));
}

@IpsTableStructure(name = "FooTable", type = TableStructureKind.MULTIPLE_CONTENTS, columns = {})
private class FooTable extends Table<FooTableRow> {

Expand Down Expand Up @@ -294,6 +324,9 @@ private class Product extends ProductComponent {
public final FooTable TABLE1 = new FooTable();
public final BarTable TABLE2 = new BarTable();

private String table1Name = "Foo";
private String table2Name = "Bar";

public Product() {
super(repository, "id", "kindId", "versionId");
}
Expand All @@ -305,7 +338,12 @@ public FooTable getTable1() {

@SuppressWarnings("unused")
public String getTable1Name() {
return "Foo";
return table1Name;
}

@SuppressWarnings("unused")
public void setTable1Name(String name) {
table1Name = name;
}

@IpsTableUsage(name = "table2")
Expand All @@ -315,7 +353,12 @@ public BarTable getTable2() {

@SuppressWarnings("unused")
public String getTable2Name() {
return "Bar";
return table2Name;
}

@SuppressWarnings("unused")
public void setTable2Name(String name) {
table2Name = name;
}

@IpsTableUsage(name = "multitable")
Expand Down Expand Up @@ -344,6 +387,8 @@ private class ProductGen extends ProductComponentGeneration {

public final BarTable TABLE_GEN = new BarTable();

private String tableGenName = "Bar";

public ProductGen(Product product) {
super(product);
}
Expand All @@ -355,7 +400,7 @@ public BarTable getTableGen() {

@SuppressWarnings("unused")
public String getTableGenName() {
return "Bar";
return tableGenName;
}
}

Expand All @@ -365,14 +410,21 @@ private class ChildProduct extends Product {

public final FooTable TABLE3 = new FooTable();

private String table3Name = "Foo";

@IpsTableUsage(name = "table3")
public FooTable getTable3() {
return TABLE3;
}

@SuppressWarnings("unused")
public String getTable3Name() {
return "Foo";
return table3Name;
}

@SuppressWarnings("unused")
public void setTable3Name(String name) {
table3Name = name;
}
}
}

0 comments on commit 7a8a797

Please sign in to comment.