Commit 1056baa0 authored by Hellmich, Christoph's avatar Hellmich, Christoph
Browse files

Change architecture

See doc\klassendiagramm.png for an overview
parent 1f5a6115
{
"relationships": [
{
"relationshipId": 1,
"relationshipName": "origin",
"otherEntityName": "statement",
"relationshipType": "many-to-one",
"otherEntityField": "id"
}
],
"fields": [],
"changelogDate": "20160321161721",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
{
"relationships": [
{
"relationshipId": 1,
"relationshipName": "statement",
"otherEntityName": "statement",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "conditional"
},
{
"relationshipId": 2,
"relationshipName": "nextStep",
"otherEntityName": "step",
"relationshipType": "many-to-one",
"otherEntityField": "id"
}
],
"fields": [],
"changelogDate": "20160321161717",
"dto": "no",
"pagination": "no",
"service": "no"
}
......@@ -6,16 +6,83 @@
"otherEntityName": "step",
"relationshipType": "many-to-one",
"otherEntityField": "id"
},
{
"relationshipId": 2,
"relationshipName": "nextStep",
"otherEntityName": "step",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "element"
},
{
"relationshipId": 3,
"relationshipName": "element",
"otherEntityName": "element",
"relationshipType": "many-to-one",
"otherEntityField": "id"
},
{
"relationshipId": 4,
"relationshipName": "options",
"otherEntityName": "options",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "element"
},
{
"relationshipId": 5,
"relationshipName": "validation",
"otherEntityName": "validation",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "element"
}
],
"fields": [
{
"fieldId": 1,
"fieldName": "settings",
"fieldName": "type",
"fieldType": "String"
},
{
"fieldId": 2,
"fieldName": "name",
"fieldType": "String"
},
{
"fieldId": 3,
"fieldName": "displayName",
"fieldType": "String"
},
{
"fieldId": 4,
"fieldName": "placeholder",
"fieldType": "String"
},
{
"fieldId": 5,
"fieldName": "value",
"fieldType": "String"
},
{
"fieldId": 6,
"fieldName": "tooltip",
"fieldType": "String"
},
{
"fieldId": 7,
"fieldName": "nolabel",
"fieldType": "Boolean"
},
{
"fieldId": 8,
"fieldName": "hidden",
"fieldType": "Boolean"
},
{
"fieldId": 9,
"fieldName": "formRow",
"fieldType": "Integer"
}
......
{
"relationships": [],
"fields": [],
"changelogDate": "20160321161720",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
{
"relationships": [],
"fields": [],
"changelogDate": "20160321161722",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
{
"relationships": [],
"fields": [],
"changelogDate": "20160321161724",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
{
"relationships": [],
"fields": [],
"changelogDate": "20160321161723",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
{
"relationships": [],
"fields": [
{
"fieldId": 1,
"fieldName": "minlength",
"fieldType": "String"
},
{
"fieldId": 2,
"fieldName": "maxlength",
"fieldType": "String"
},
{
"fieldId": 3,
"fieldName": "min",
"fieldType": "String"
},
{
"fieldId": 4,
"fieldName": "max",
"fieldType": "String"
},
{
"fieldId": 5,
"fieldName": "pattern",
"fieldType": "String"
},
{
"fieldId": 6,
"fieldName": "required",
"fieldType": "String"
}
],
"changelogDate": "20160725162739",
"dto": "no",
"pagination": "no",
"service": "no"
}
......@@ -11,15 +11,16 @@
"fields": [
{
"fieldId": 1,
"fieldName": "state",
"fieldType": "State",
"fieldValues": "TRUE,FALSE,UNDEFINDED",
"fieldValidateRules": [
"required"
]
"fieldName": "value",
"fieldType": "String"
},
{
"fieldId": 2,
"fieldName": "text",
"fieldType": "String"
}
],
"changelogDate": "20160321161718",
"changelogDate": "20160725165720",
"dto": "no",
"pagination": "no",
"service": "no"
......
{
"relationships": [],
"fields": [],
"changelogDate": "20160321161719",
"dto": "no",
"pagination": "no",
"service": "no"
}
\ No newline at end of file
......@@ -13,13 +13,6 @@
"otherEntityName": "element",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "step"
},
{
"relationshipId": 3,
"relationshipName": "conditional",
"otherEntityName": "conditional",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "nextStep"
}
],
"fields": [
......
{
"relationships": [
{
"relationshipId": 1,
"relationshipName": "messages",
"otherEntityName": "messages",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "validation"
}
],
"fields": [
{
"fieldId": 1,
"fieldName": "minlength",
"fieldType": "Integer"
},
{
"fieldId": 2,
"fieldName": "maxlength",
"fieldType": "Integer"
},
{
"fieldId": 3,
"fieldName": "min",
"fieldType": "Integer"
},
{
"fieldId": 4,
"fieldName": "max",
"fieldType": "Integer"
},
{
"fieldId": 5,
"fieldName": "pattern",
"fieldType": "String"
},
{
"fieldId": 6,
"fieldName": "required",
"fieldType": "Boolean"
}
],
"changelogDate": "20160725162738",
"dto": "no",
"pagination": "no",
"service": "no"
}
......@@ -136,318 +136,6 @@ Ein Service kann mit `yo jhipster:service <Name des Services>` erstellt werden (
[TODO]
## Vererbungen erstellen
JHipster bietet keine Möglichkeit Vererbungshierarchien zwischen Entitäten anzugeben. Daher wurden die Entitäten nach der Generierung manuell entsprechend angepasst. Nachfolgend sind die vorgenommenen Änderungen von der Element-Entität bis zu den LogicalConnectiveOr/And/Or-Entität (vlg. Abbildung) kurz dargestellt.
![Entitäten](entities.gif)
### Element-Entität
**Erstelle** die Datei `src\main\java\org\gesis\dda\wizard\repository\ElementBaseRepository.java`:
```java
package org.gesis.dda.wizard.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import gesis.org.myapp.domain.Element;
@NoRepositoryBean
public interface ElementBaseRepository<T extends Element> extends JpaRepository<T, Long> {
}
```
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\repository\ElementRepository.java`:
```java
public interface ElementRepository extends ElementBaseRepository<Element> {
}
```
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\domain\Element.java`:
```java
@Entity
@Inheritance
@DiscriminatorColumn(name = "element_type")
@Table(name = "element")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Element implements Serializable {
// ...
}
```
**Erweitere** die Datei `src\main\resources\config\liquibase\changelog\20160321161714_added_entity_Element.xml`:
```xml
<column name="element_type" type="varchar(31)">
<constraints nullable="false" />
</column>
```
### SimpleElement-Entität
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\domain\SimpleElement.java`:
```java
package org.gesis.dda.wizard.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
/**
* A SimpleElement.
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SimpleElement extends Element {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SimpleElement simpleElement = (SimpleElement) o;
if(simpleElement.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), simpleElement.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "SimpleElement{" +
"id=" + getId() +
'}';
}
}
```
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\repository\SimpleElementRepository.java`:
```java
public interface SimpleElementRepository extends ElementBaseRepository<SimpleElement> {
}
```
**Bearbeite** die Datei `src\main\resources\config\liquibase\master.xml`:
```xml
<!-- <include file="classpath:config/liquibase/changelog/20160317131756_added_entity_SimpleStatement.xml" relativeToChangelogFile="false"/> -->
```
### Statement-Entität
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\domain\Statement.java`:
```java
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Statement extends Element {
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "state", nullable = false)
private State state;
@ManyToOne
@JoinColumn(name = "element_id")
private Element element;
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public Element getElement() {
return element;
}
public void setElement(Element element) {
this.element = element;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Statement statement = (Statement) o;
if(statement.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), statement.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "Statement{" +
"id=" + getId() +
", state='" + state + "'" +
'}';
}
}
```
**Bearbeite** die Datei `src\main\java\org\gesis\dda\wizard\repository\StatementRepository.java`:
```java
public interface StatementRepository extends ElementBaseRepository<Statement> {
}
```
**Bearbeite** die Datei `src\main\resources\config\liquibase\master.xml`:
```xml
<!-- <include file="classpath:config/liquibase/changelog/20160317131755_added_entity_Statement.xml" relativeToChangelogFile="false"/> -->
```
**Bearbeite** die Datei `src\main\resources\config\liquibase\changelog\20160317131751_added_entity_Element.xml`:
```xml
<!--
Added the entity Element.
-->
<changeSet id="20160321161714" author="jhipster">
<createTable tableName="element">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="element_type" type="varchar(31)">
<constraints nullable="false" />
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="step_id" type="bigint"/>
<column name="template_id" type="bigint"/>
<column name="state" type="varchar(255)"/>
<column name="element_id" type="bigint"/>
<!-- jhipster-needle-liquibase-add-column - Jhipster will add columns here, do not remove-->
</createTable>
<addForeignKeyConstraint baseColumnNames="step_id"
baseTableName="element"
constraintName="fk_element_step_id"
referencedColumnNames="id"
referencedTableName="step"/>
<addForeignKeyConstraint baseColumnNames="template_id"
baseTableName="element"
constraintName="fk_element_template_id"
referencedColumnNames="id"
referencedTableName="element_template"/>
<addForeignKeyConstraint baseColumnNames="element_id"
baseTableName="element"
constraintName="fk_element_element_id"
referencedColumnNames="id"
referencedTableName="element"/>
```
**Bearbeite** die Datei `src\main\resources\config\liquibase\changelog\20160317131758_added_entity_CompoundStatement.xml`:
```xml
<addForeignKeyConstraint baseColumnNames="origin_id"
baseTableName="compound_statement"
constraintName="fk_compoundstatement_origin_id"
referencedColumnNames="id"
referencedTableName="element"/>
```
**Bearbeite** die Datei `src\main\resources\config\liquibase\changelog\20160317131754_added_entity_Conditional.xml`:
```xml
<addForeignKeyConstraint baseColumnNames="statement_id"
baseTableName="conditional"
constraintName="fk_conditional_statement_id"
referencedColumnNames="id"
referencedTableName="element"/>
```
### EqualValueStatement-Entität
Siehe SimpleElement-Entität.
### CompoundStatement-Entität
Siehe Statement-Entität.
### LogicalConnectiveX-Entitäten
Siehe SimpleElement-Entität.
Weitere Informationen:
- [Java Persistence/Inheritance](https://en.wikibooks.org/wiki/Java_Persistence/Inheritance)
- [Handling entities inheritance with Spring Data JPA](http://blog.netgloo.com/2014/12/18/handling-entities-inheritance-with-spring-data-jpa/)
- [Transaction Management](http://docs.spring.io/autorepo/docs/spring/4.2.x/spring-framework-reference/html/transaction.html)
---
## JSON-Snippets zum Testen der Entitäten mittels API (swagger)
Element, SimpleElement
```json
{
"name": "string"
}
```
Statement, EqualValueStatement, CompoundStatement, LogicalConnectiveOr, LogicalConnectiveAnd, LogicalConnectiveNot
```json
{
"name": "string",
"state": "TRUE"
}
```
Statement, EqualValueStatement, CompoundStatement, LogicalConnectiveOr, LogicalConnectiveAnd, LogicalConnectiveNot
```json
{
"element": {
"id": 1
},
"name": "string",
"state": "TRUE"
}
```
CompoundStatement, LogicalConnectiveOr, LogicalConnectiveAnd, LogicalConnectiveNot
```json
{
"element": {
"id": 1
},
"origin": {