Commit 9879c594 authored by Volker Krause's avatar Volker Krause
Browse files

Remove old aggregation setting

parent 2de64c2b
......@@ -36,21 +36,9 @@ public:
QString name;
int internalId = -1;
SchemaEntry::DataType dataType = SchemaEntry::Scalar;
SchemaEntry::AggregationType aggregation = SchemaEntry::None;
QVector<SchemaEntryElement> elements;
};
static const struct {
SchemaEntry::AggregationType type;
const char *name;
} aggregation_types_table[] {
{ SchemaEntry::None, "none" },
{ SchemaEntry::Category, "category" },
{ SchemaEntry::RatioSet, "ratio_set" },
{ SchemaEntry::Numeric, "numeric" },
{ SchemaEntry::XY, "xy" }
};
static const struct {
SchemaEntry::DataType type;
const char *name;
......@@ -73,7 +61,6 @@ bool SchemaEntry::operator==(const SchemaEntry &other) const
return d->name == other.d->name
&& d->internalId == other.d->internalId
&& d->dataType == other.d->dataType
&& d->aggregation == other.d->aggregation
&& d->elements == other.d->elements;
}
......@@ -107,16 +94,6 @@ void SchemaEntry::setDataType(SchemaEntry::DataType type)
d->dataType = type;
}
SchemaEntry::AggregationType SchemaEntry::aggregationType() const
{
return d->aggregation;
}
void SchemaEntry::setAggregationType(SchemaEntry::AggregationType type)
{
d->aggregation = type;
}
QVector<SchemaEntryElement> SchemaEntry::elements() const
{
return d->elements;
......@@ -146,7 +123,6 @@ QJsonObject SchemaEntry::toJsonObject() const
QString t;
obj.insert(QStringLiteral("type"), QLatin1String(data_types_table[d->dataType].name));
obj.insert(QStringLiteral("aggregationType"), QLatin1String(aggregation_types_table[d->aggregation].name));
QJsonArray array;
for (const auto &element : qAsConst(d->elements))
......@@ -165,7 +141,6 @@ QVector<SchemaEntry> SchemaEntry::fromJson(const QJsonArray &array)
SchemaEntry entry;
entry.setName(obj.value(QStringLiteral("name")).toString());
entry.setDataType(Util::stringToEnum<DataType>(obj.value(QLatin1String("type")).toString(), data_types_table));
entry.setAggregationType(Util::stringToEnum<AggregationType>(obj.value(QLatin1String("aggregationType")).toString(), aggregation_types_table));
entry.setElements(SchemaEntryElement::fromJson(obj.value(QLatin1String("elements")).toArray()));
res.push_back(entry);
......
......@@ -66,15 +66,6 @@ public:
};
Q_ENUM(DataType)
enum AggregationType {
None,
Category,
RatioSet,
Numeric,
XY
};
Q_ENUM(AggregationType)
SchemaEntry();
SchemaEntry(const SchemaEntry &entry);
~SchemaEntry();
......@@ -88,9 +79,6 @@ public:
QString name() const;
void setName(const QString& name);
AggregationType aggregationType() const;
void setAggregationType(AggregationType type);
DataType dataType() const;
void setDataType(DataType type);
......
......@@ -83,7 +83,7 @@ void SchemaModel::deleteRow(const QModelIndex &idx)
int SchemaModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
return 2;
}
int SchemaModel::rowCount(const QModelIndex& parent) const
......@@ -106,11 +106,9 @@ QVariant SchemaModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole || role == Qt::EditRole)
return m_product.schema().at(index.row()).name();
break;
case 2:
case 1:
if (role == Qt::DisplayRole)
return Util::enumToString(m_product.schema().at(index.row()).aggregationType());
if (role == Qt::EditRole)
return QVariant::fromValue(m_product.schema().at(index.row()).aggregationType());
break;
}
} else {
const auto entry = m_product.schema().at(index.internalId());
......@@ -136,7 +134,6 @@ QVariant SchemaModel::headerData(int section, Qt::Orientation orientation, int r
switch (section) {
case 0: return tr("Name");
case 1: return tr("Type");
case 2: return tr("Aggregation");
}
}
return QAbstractItemModel::headerData(section, orientation, role);
......@@ -147,9 +144,7 @@ Qt::ItemFlags SchemaModel::flags(const QModelIndex &index) const
const auto baseFlags = QAbstractItemModel::flags(index);
if (!index.isValid())
return baseFlags;
if ((index.internalId() == TOPLEVEL && index.column() != 1) || (index.internalId() != TOPLEVEL && index.column() < 2))
return baseFlags | Qt::ItemIsEditable;
return baseFlags;
return baseFlags | Qt::ItemIsEditable;
}
bool SchemaModel::setData(const QModelIndex &index, const QVariant &value, int role)
......@@ -165,8 +160,6 @@ bool SchemaModel::setData(const QModelIndex &index, const QVariant &value, int r
case 0:
entry.setName(value.toString());
break;
case 2:
entry.setAggregationType(value.value<SchemaEntry::AggregationType>());
break;
}
} else {
......
......@@ -23,7 +23,6 @@ class SchemaEntry
{
public $name;
public $type;
public $aggregationType;
public $elements = array();
private $entryId = -1;
......@@ -64,7 +63,7 @@ class SchemaEntry
static public function loadSchema(Datastore $db, Product &$product)
{
$stmt = $db->prepare('SELECT
product_schema.id, product_schema.name, product_schema.type, product_schema.aggregation, schema_elements.name, schema_elements.type
product_schema.id, product_schema.name, product_schema.type, schema_elements.name, schema_elements.type
FROM schema_elements JOIN product_schema ON (product_schema.id = schema_elements.schemaId)
WHERE product_schema.productId = :productId
ORDER BY product_schema.id
......@@ -81,11 +80,10 @@ class SchemaEntry
$entry->entryId = $row[0];
$entry->name = $row[1];
$entry->type = $row[2];
$entry->aggregationType = $row[3];
}
$elem = new SchemaEntryElement($entry);
$elem->name = $row[4];
$elem->type = $row[5];
$elem->name = $row[3];
$elem->type = $row[4];
array_push($entry->elements, $elem);
}
if ($entry->isValid())
......@@ -98,14 +96,13 @@ class SchemaEntry
public function insert(Datastore $db, $productId)
{
$stmt = $db->prepare('INSERT INTO
product_schema (productId, name, type, aggregation)
VALUES (:productId, :name, :type, :aggregation)
product_schema (productId, name, type)
VALUES (:productId, :name, :type)
');
$db->execute($stmt, array(
':productId' => $productId,
':name' => $this->name,
':type' => $this->type,
':aggregation' => $this->aggregationType
));
$this->entryId = $db->pdoHandle()->lastInsertId();
......@@ -128,15 +125,6 @@ class SchemaEntry
public function update(Datastore $db, SchemaEntry $newEntry)
{
// TODO reject type changes
$stmt = $db->prepare('
UPDATE product_schema SET
aggregation = :aggregation
WHERE id = :id'
);
$db->execute($stmt, array(
':aggregation' => $newEntry->aggregationType,
':id' => $this->entryId
));
// update elements
$oldElements = array();
......@@ -182,12 +170,11 @@ class SchemaEntry
{
$entries = array();
foreach ($jsonArray as $jsonObj) {
if (!property_exists($jsonObj, 'name') || !property_exists($jsonObj, 'type') || !property_exists($jsonObj, 'aggregationType'))
if (!property_exists($jsonObj, 'name') || !property_exists($jsonObj, 'type'))
throw new RESTException('Incomplete schema entry object.', 400);
$e = new SchemaEntry($product);
$e->name = strval($jsonObj->name);
$e->type = strval($jsonObj->type);
$e->aggregationType = strval($jsonObj->aggregationType);
if (property_exists($jsonObj, 'elements'))
$e->elements = SchemaEntryElement::fromJson($jsonObj->elements, $e);
if (!$e->isValid())
......
......@@ -107,7 +107,6 @@ private slots:
// add new product
SchemaEntry entry;
entry.setName(QStringLiteral("entry1"));
entry.setAggregationType(SchemaEntry::Category);
SchemaEntryElement elem1;
elem1.setName(QStringLiteral("elem11"));
entry.setElements({elem1});
......
......@@ -65,7 +65,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entry1",
"type": "scalar",
"aggregationType": "category",
"elements" : [
{ "name": "element1", "type": "int" },
{ "name": "element2", "type": "bool" }
......@@ -82,7 +81,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$entry = $p->schema[0];
$this->assertEquals($entry->name, 'entry1');
$this->assertEquals($entry->type, 'scalar');
$this->assertEquals($entry->aggregationType, 'category');
$this->assertEquals(2, count($entry->elements));
$elem = $entry->elements[1];
......@@ -100,7 +98,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$entry = new SchemaEntry($p);
$entry->name = 'entry1';
$entry->type = 'list';
$entry->aggregationType = 'numeric';
$elem = new SchemaEntryElement($entry);
$elem->name = 'element3';
$elem->type = 'number';
......@@ -117,7 +114,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entry1",
"type": "list",
"aggregationType": "numeric",
"elements" : [
{ "name": "element3", "type": "number" }
]
......@@ -148,7 +144,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$this->assertInstanceOf(SchemaEntry::class, $entry1);
$this->assertEquals($entry1->name, 'entry1');
$this->assertEquals($entry1->type, 'scalar');
$this->assertEquals($entry1->aggregationType, 'category');
$this->assertEquals(2, count($entry1->elements));
$elem = $entry1->elements[1];
$this->assertInstanceOf(SchemaEntryElement::class, $elem);
......@@ -158,7 +153,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$this->assertInstanceOf(SchemaEntry::class, $entry2);
$this->assertEquals($entry2->name, 'entry2');
$this->assertEquals($entry2->type, 'list');
$this->assertEquals($entry2->aggregationType, 'xy');
$this->assertCount(2, $p->aggregation);
}
......@@ -183,7 +177,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$this->assertInstanceOf(SchemaEntry::class, $entry1);
$this->assertEquals($entry1->name, 'entry1');
$this->assertEquals($entry1->type, 'scalar');
$this->assertEquals($entry1->aggregationType, 'category');
$elem = $entry1->elements[1];
$this->assertInstanceOf(SchemaEntryElement::class, $elem);
$this->assertEquals('element12', $elem->name);
......@@ -192,7 +185,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
$this->assertInstanceOf(SchemaEntry::class, $entry2);
$this->assertEquals($entry2->name, 'entry2');
$this->assertEquals($entry2->type, 'list');
$this->assertEquals($entry2->aggregationType, 'xy');
}
public function testProductInsert()
......@@ -203,7 +195,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryA",
"type": "scalar",
"aggregationType": "category",
"elements" : [
{ "name": "elementA1", "type": "int" },
{ "name": "elementA2", "type": "bool" }
......@@ -212,7 +203,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryB",
"type": "map",
"aggregationType": "ratio_set",
"elements" : [
{ "name": "elementB1", "type": "number" },
{ "name": "elementB2", "type": "string" }
......@@ -251,7 +241,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryA",
"type": "scalar",
"aggregationType": "none",
"elements" : [
{ "name": "elementA1", "type": "int" },
{ "name": "elementA2", "type": "bool" }
......@@ -260,7 +249,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryB",
"type": "list",
"aggregationType": "ratio_set",
"elements" : [
{ "name": "elementB1", "type": "number" },
{ "name": "elementB2", "type": "string" }
......@@ -290,7 +278,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryA",
"type": "scalar",
"aggregationType": "category",
"elements" : [
{ "name": "elementA1", "type": "int" }
]
......@@ -298,7 +285,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entryC",
"type": "map",
"aggregationType": "xy",
"elements" : [
{ "name": "elementC1", "type": "number" },
{ "name": "elementC2", "type": "number" }
......@@ -337,7 +323,6 @@ class ProductTest extends PHPUnit_Extensions_Database_TestCase
{
"name": "entry1",
"type": "list",
"aggregationType": "numeric",
"elements" : [
{ "name": "element3", "type": "number" }
]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment