Revision: 3759
Author: [email protected]
Date: Tue Jul 20 08:10:07 2010
Log: Created a new FormulaMetricCalculation object to be used for Architect
EE. This object exists on individual projects and not on the server
workspace.
Also, made test classes for BusinessDefinition and FormulaMetricCalculation.
http://code.google.com/p/power-architect/source/detail?r=3759
Added:
/trunk/regress/ca/sqlpower/architect/enterprise/BusinessDefinitionTest.java
/trunk/regress/ca/sqlpower/architect/enterprise/FormulaMetricCalculationTest.java
/trunk/src/main/java/ca/sqlpower/architect/enterprise/FormulaMetricCalculation.java
Modified:
/trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
/trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
=======================================
--- /dev/null
+++
/trunk/regress/ca/sqlpower/architect/enterprise/BusinessDefinitionTest.java
Tue Jul 20 08:10:07 2010
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.enterprise;
+
+import ca.sqlpower.architect.util.ArchitectNewValueMaker;
+import ca.sqlpower.object.PersistedSPObjectTest;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.testutil.NewValueMaker;
+
+public class BusinessDefinitionTest extends PersistedSPObjectTest {
+
+ private BusinessDefinition busDef;
+
+ public BusinessDefinitionTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ busDef = (BusinessDefinition) createNewValueMaker(
+ getRootObject(), getPLIni()).makeNewValue(
+ BusinessDefinition.class,
null, "BusinessDefinitionTest");
+ }
+
+ @Override
+ protected Class<? extends SPObject> getChildClassType() {
+ return null;
+ }
+
+ @Override
+ public SPObject getSPObjectUnderTest() {
+ return busDef;
+ }
+
+ @Override
+ public NewValueMaker createNewValueMaker(SPObject root,
DataSourceCollection<SPDataSource> dsCollection) {
+ return new ArchitectNewValueMaker(root, dsCollection);
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/regress/ca/sqlpower/architect/enterprise/FormulaMetricCalculationTest.java
Tue Jul 20 08:10:07 2010
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.enterprise;
+
+import ca.sqlpower.architect.util.ArchitectNewValueMaker;
+import ca.sqlpower.object.PersistedSPObjectTest;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.testutil.NewValueMaker;
+
+public class FormulaMetricCalculationTest extends PersistedSPObjectTest {
+
+ private FormulaMetricCalculation fmc;
+
+ public FormulaMetricCalculationTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ fmc = (FormulaMetricCalculation) createNewValueMaker(
+ getRootObject(), getPLIni()).makeNewValue(
+ FormulaMetricCalculation.class,
null, "FormulaMetricCalculationTest");
+ }
+
+ @Override
+ protected Class<? extends SPObject> getChildClassType() {
+ return null;
+ }
+
+ @Override
+ public SPObject getSPObjectUnderTest() {
+ return fmc;
+ }
+
+ @Override
+ public NewValueMaker createNewValueMaker(SPObject root,
DataSourceCollection<SPDataSource> dsCollection) {
+ return new ArchitectNewValueMaker(root, dsCollection);
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/FormulaMetricCalculation.java
Tue Jul 20 08:10:07 2010
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.enterprise;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import ca.sqlpower.object.AbstractSPObject;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.object.annotation.Accessor;
+import ca.sqlpower.object.annotation.Constructor;
+import ca.sqlpower.object.annotation.ConstructorParameter;
+import ca.sqlpower.object.annotation.Mutator;
+
+/**
+ * This {...@link SPObject} represents a formula or metric calculation.
+ */
+public class FormulaMetricCalculation extends AbstractSPObject {
+
+ /**
+ * Defines an absolute ordering of the child types of this class.
+ *
+ * IMPORTANT!: When changing this, ensure you maintain the order
specified by {...@link #getChildren()}
+ */
+ public static final List<Class<? extends SPObject>> allowedChildTypes =
+ Collections.emptyList();
+
+ /**
+ * {...@link #getFormula()}
+ */
+ private String formula;
+
+ /**
+ * {...@link #getDescription()}
+ */
+ private String description;
+
+ /**
+ * Creates a new formula or metric calculation.
+ *
+ * @param name
+ * The name of the formula. This value cannot be null.
+ * @param formula
+ * The formula. This value cannot be null.
+ * @param description
+ * The description of the formula. This value cannot be
null.
+ */
+ @Constructor
+ public FormulaMetricCalculation(
+ @ConstructorParameter(propertyName="name") @Nonnull String
name,
+ @ConstructorParameter(propertyName="formula") @Nonnull String
formula,
+ @ConstructorParameter(propertyName="description") @Nonnull
String description) {
+ setName(name);
+ this.formula = formula;
+ this.description = description;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param formula
+ * The {...@link FormulaMetricCalculation} to copy.
+ */
+ public FormulaMetricCalculation(FormulaMetricCalculation formula) {
+ this(formula.getName(), formula.getFormula(),
formula.getDescription());
+ }
+
+ @Override
+ public List<? extends SPObject> getChildren() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void removeDependency(SPObject dependency) {
+ // No operation.
+ }
+
+ @Override
+ public List<? extends SPObject> getDependencies() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<Class<? extends SPObject>> getAllowedChildTypes() {
+ return allowedChildTypes;
+ }
+
+ @Override
+ protected boolean removeChildImpl(SPObject child) {
+ return false;
+ }
+
+ /**
+ * Gets the formula.
+ * @return The {...@link String} formula.
+ */
+ @Accessor(isInteresting=true)
+ public String getFormula() {
+ return formula;
+ }
+
+ /**
+ * Sets the formula.
+ *
+ * @param formula
+ * The {...@link String} formula. This value cannot be null.
+ */
+ @Mutator
+ public void setFormula(@Nonnull String formula) {
+ String oldFormula = this.formula;
+ this.formula = formula;
+ firePropertyChange("formula", oldFormula, formula);
+ }
+
+ /**
+ * Gets the description of this formula.
+ *
+ * @return The description of the formula.
+ */
+ @Accessor(isInteresting=true)
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of this formula.
+ *
+ * @param description
+ * The {...@link String} description of the formula.
+ */
+ @Mutator
+ public void setDescription(@Nonnull String description) {
+ String oldDescription = this.description;
+ this.description = description;
+ firePropertyChange("description", oldDescription, description);
+ }
+
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
Fri Jul 16 13:23:39 2010
+++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
Tue Jul 20 08:10:07 2010
@@ -28,7 +28,9 @@
import ca.sqlpower.architect.ddl.critic.CriticGrouping;
import ca.sqlpower.architect.ddl.critic.CriticManager;
import ca.sqlpower.architect.ddl.critic.impl.AlphaNumericNameCritic;
+import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.architect.enterprise.FormulaMetricCalculation;
import ca.sqlpower.architect.etl.kettle.KettleSettings;
import ca.sqlpower.architect.olap.MondrianModel.Cube;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
@@ -182,6 +184,19 @@
} else {
return Severity.ERROR;
}
+ } else if (valueType == BusinessDefinition.class) {
+ String term = (String) makeNewValue(String.class,
null, "BusinessDefinition term");
+ String definition = (String) makeNewValue(String.class,
null, "BusinessDefinition definition");
+ BusinessDefinition busDef = new BusinessDefinition(term,
definition);
+ valueMakerProject.addBusinessDefinition(busDef, 0);
+ return busDef;
+ } else if (valueType == FormulaMetricCalculation.class) {
+ String name = (String) makeNewValue(String.class,
null, "FormulaMetricCalculation name");
+ String formula = (String) makeNewValue(String.class,
null, "FormulaMetricCalculation formula");
+ String description = (String) makeNewValue(String.class,
null, "FormulaMetricCalculation description");
+ FormulaMetricCalculation fmc = new
FormulaMetricCalculation(name, formula, description);
+ valueMakerProject.addFormulaMetricCalculation(fmc, 0);
+ return fmc;
} else {
return super.makeNewValue(valueType, oldVal, propName);
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Fri
Jul 16 07:18:35 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Tue
Jul 20 08:10:07 2010
@@ -26,6 +26,7 @@
import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.architect.enterprise.FormulaMetricCalculation;
import ca.sqlpower.architect.profile.ProfileManager;
import ca.sqlpower.enterprise.client.Group;
import ca.sqlpower.enterprise.client.User;
@@ -71,7 +72,8 @@
public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections
.unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class, ProfileManager.class,
- ProjectSettings.class, User.class, Group.class,
BusinessDefinition.class)));
+ ProjectSettings.class, User.class, Group.class,
+ BusinessDefinition.class,
FormulaMetricCalculation.class)));
/**
* There is a 1:1 ratio between the session and the project.
@@ -84,10 +86,12 @@
private List<User> users = new ArrayList<User>();
private List<Group> groups = new ArrayList<Group>();
private final List<UserDefinedSQLType> sqlTypes = new
ArrayList<UserDefinedSQLType>();
- private final List<SPObjectSnapshot> sqlTypeSnapshots = new
ArrayList<SPObjectSnapshot>();
+ private final List<SPObjectSnapshot<?>> sqlTypeSnapshots = new
ArrayList<SPObjectSnapshot<?>>();
private final List<DomainCategory> domainCategories = new
ArrayList<DomainCategory>();
+ // Metadata children
private final List<BusinessDefinition> businessDefinitions = new
ArrayList<BusinessDefinition>();
+ private final List<FormulaMetricCalculation> formulas = new
ArrayList<FormulaMetricCalculation>();
/**
* The current integrity watcher on the project.
@@ -239,44 +243,92 @@
@Override
protected boolean removeChildImpl(SPObject child) {
if (child instanceof User) {
- int index = users.indexOf((User) child);
- users.remove((User) child);
+ return removeUser((User) child);
+ } else if (child instanceof Group) {
+ return removeGroup((Group) child);
+ } else if (child instanceof UserDefinedSQLType) {
+ return removeSQLType((UserDefinedSQLType) child);
+ } else if (child instanceof DomainCategory) {
+ return removeDomainCategory((DomainCategory) child);
+ } else if (child instanceof SPObjectSnapshot) {
+ return removeSPObjectSnapshot((SPObjectSnapshot<?>) child);
+ } else if (child instanceof BusinessDefinition) {
+ return removeBusinessDefinition((BusinessDefinition) child);
+ } else if (child instanceof FormulaMetricCalculation) {
+ return
removeFormulaMetricCalculation((FormulaMetricCalculation) child);
+ }
+ return false;
+ }
+
+ public boolean removeUser(User child) {
+ int index = users.indexOf(child);
+ boolean removed = users.remove(child);
+ if (removed) {
fireChildRemoved(User.class, child, index);
child.setParent(null);
- return true;
- } else if (child instanceof Group) {
- int index = users.indexOf((Group) child);
- groups.remove((Group) child);
+ }
+ return removed;
+ }
+
+ public boolean removeGroup(Group child) {
+ int index = users.indexOf(child);
+ boolean removed = groups.remove(child);
+ if (removed) {
fireChildRemoved(Group.class, child, index);
child.setParent(null);
- return true;
- } else if (child instanceof UserDefinedSQLType) {
- int index = sqlTypes.indexOf((UserDefinedSQLType) child);
- sqlTypes.remove((UserDefinedSQLType) child);
+ }
+ return removed;
+ }
+
+ public boolean removeSQLType(UserDefinedSQLType child) {
+ int index = sqlTypes.indexOf(child);
+ boolean removed = sqlTypes.remove(child);
+ if (removed) {
fireChildRemoved(UserDefinedSQLType.class, child, index);
child.setParent(null);
- return true;
- } else if (child instanceof DomainCategory) {
- int index = domainCategories.indexOf((DomainCategory) child);
- domainCategories.remove((DomainCategory) child);
+ }
+ return removed;
+ }
+
+ public boolean removeDomainCategory(DomainCategory child) {
+ int index = domainCategories.indexOf(child);
+ boolean removed = domainCategories.remove(child);
+ if (removed) {
fireChildRemoved(DomainCategory.class, child, index);
child.setParent(null);
- return true;
- } else if (child instanceof SPObjectSnapshot) {
- int index = sqlTypeSnapshots.indexOf((SPObjectSnapshot) child);
- sqlTypeSnapshots.remove((SPObjectSnapshot) child);
+ }
+ return removed;
+ }
+
+ public boolean removeSPObjectSnapshot(SPObjectSnapshot<?> child) {
+ int index = sqlTypeSnapshots.indexOf(child);
+ boolean removed = sqlTypeSnapshots.remove(child);
+ if (removed) {
fireChildRemoved(SPObjectSnapshot.class, child, index);
child.setParent(null);
- return true;
- } else if (child instanceof BusinessDefinition) {
- int index = businessDefinitions.indexOf((BusinessDefinition)
child);
- businessDefinitions.remove((BusinessDefinition) child);
+ }
+ return removed;
+ }
+
+ public boolean removeBusinessDefinition(BusinessDefinition child) {
+ int index = businessDefinitions.indexOf(child);
+ boolean removed = businessDefinitions.remove(child);
+ if (removed) {
fireChildRemoved(BusinessDefinition.class, child, index);
child.setParent(null);
- return true;
- }
- return false;
- }
+ }
+ return removed;
+ }
+
+ public boolean removeFormulaMetricCalculation(FormulaMetricCalculation
child) {
+ int index = formulas.indexOf(child);
+ boolean removed = formulas.remove(child);
+ if (removed) {
+ fireChildRemoved(FormulaMetricCalculation.class, child, index);
+ child.setParent(null);
+ }
+ return removed;
+ }
@Transient @Accessor
public ArchitectSession getSession() throws SessionNotFoundException {
@@ -318,6 +370,7 @@
allChildren.addAll(users);
allChildren.addAll(groups);
allChildren.addAll(businessDefinitions);
+ allChildren.addAll(formulas);
return allChildren;
}
@@ -346,9 +399,11 @@
} else if (child instanceof DomainCategory) {
addDomainCategory((DomainCategory) child, index);
} else if (child instanceof SPObjectSnapshot) {
- addSPObjectSnapshot((SPObjectSnapshot) child, index);
+ addSPObjectSnapshot((SPObjectSnapshot<?>) child, index);
} else if (child instanceof BusinessDefinition) {
addBusinessDefinition((BusinessDefinition) child, index);
+ } else if (child instanceof FormulaMetricCalculation) {
+ addFormulaMetricCalculation((FormulaMetricCalculation) child,
index);
} else {
throw new IllegalArgumentException("Cannot add child of type "
+
child.getClass() + " to the project once it has been
created.");
@@ -361,6 +416,11 @@
fireChildAdded(BusinessDefinition.class, businessDefinition,
index);
}
+ public void addFormulaMetricCalculation(FormulaMetricCalculation
formula, int index) {
+ formulas.add(index, formula);
+ formula.setParent(this);
+ fireChildAdded(FormulaMetricCalculation.class, formula, index);
+ }
public void addSQLType(UserDefinedSQLType sqlType, int index) {
sqlTypes.add(index, sqlType);
@@ -368,7 +428,7 @@
fireChildAdded(UserDefinedSQLType.class, sqlType, index);
}
- protected void addSPObjectSnapshot(SPObjectSnapshot child, int index) {
+ protected void addSPObjectSnapshot(SPObjectSnapshot<?> child, int
index) {
sqlTypeSnapshots.add(index, child);
child.setParent(this);
fireChildAdded(SPObjectSnapshot.class, child, index);
@@ -380,7 +440,7 @@
}
@NonProperty
- public List<SPObjectSnapshot> getSqlTypeSnapshots() {
+ public List<SPObjectSnapshot<?>> getSqlTypeSnapshots() {
return Collections.unmodifiableList(sqlTypeSnapshots);
}
@@ -393,6 +453,11 @@
public List<BusinessDefinition> getBusinessDefinitions() {
return Collections.unmodifiableList(businessDefinitions);
}
+
+ @NonProperty
+ public List<FormulaMetricCalculation> getFormulas() {
+ return Collections.unmodifiableList(formulas);
+ }
public void addUser(User user, int index) {
users.add(index, user);
@@ -430,7 +495,6 @@
return projectSettings;
}
-
public void addDomainCategory(DomainCategory domainCategory, int
index) {
domainCategories.add(index, domainCategory);
domainCategory.setParent(this);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Fri Jul 16 07:18:35 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Tue Jul 20 08:10:07 2010
@@ -32,6 +32,7 @@
import ca.sqlpower.architect.ddl.critic.CriticManager;
import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.architect.enterprise.FormulaMetricCalculation;
import ca.sqlpower.architect.etl.kettle.KettleSettings;
import ca.sqlpower.architect.olap.OLAPRootObject;
import ca.sqlpower.architect.olap.OLAPSession;
@@ -80,7 +81,7 @@
DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class,
OLAPRootObject.class, PlayPenContentPane.class,
ProfileManager.class, ProjectSettings.class,
CriticManager.class, KettleSettings.class, User.class,
Group.class,
- BusinessDefinition.class)));
+ BusinessDefinition.class,
FormulaMetricCalculation.class)));
/**
* A hash map mapping all the descendants of this project.
@@ -212,12 +213,11 @@
@Override
protected boolean removeChildImpl(SPObject child) {
- if (super.allowsChildType(child.getClass())) {
- return super.removeChildImpl(child);
- } else if (child instanceof PlayPenContentPane) {
+ if (child instanceof PlayPenContentPane) {
return removeOLAPContentPane((PlayPenContentPane) child);
- }
- return false;
+ } else {
+ return super.removeChildImpl(child);
+ }
}
@Override @Transient @Accessor
@@ -258,6 +258,7 @@
allChildren.addAll(getUsers());
allChildren.addAll(getGroups());
allChildren.addAll(getBusinessDefinitions());
+ allChildren.addAll(getFormulas());
return allChildren;
}
@@ -279,32 +280,15 @@
}
protected void addChildImpl(SPObject child, int index) {
- if (child instanceof ProfileManager) {
- setProfileManager((ProfileManager) child);
- } else if (child instanceof PlayPenContentPane) {
+ if (child instanceof PlayPenContentPane) {
PlayPenContentPane pane = (PlayPenContentPane) child;
if (index == 0) {
setPlayPenContentPane(pane);
} else {
addOLAPContentPane(pane);
- }
- } else if (child instanceof ProjectSettings) {
- setProjectSettings((ProjectSettings) child);
- } else if (child instanceof User) {
- addUser((User) child, index);
- } else if (child instanceof Group) {
- addGroup((Group) child, index);
- } else if (child instanceof UserDefinedSQLType) {
- addSQLType((UserDefinedSQLType) child, index);
- } else if (child instanceof DomainCategory) {
- addDomainCategory((DomainCategory) child, index);
- } else if (child instanceof SPObjectSnapshot) {
- addSPObjectSnapshot((SPObjectSnapshot) child, index);
- } else if (child instanceof BusinessDefinition) {
- addBusinessDefinition((BusinessDefinition) child, index);
+ }
} else {
- throw new IllegalArgumentException("Cannot add child of type "
+
- child.getClass() + " to the project once it has been
created.");
+ super.addChildImpl(child, index);
}
}