= Vega Value Type

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


The `Vega` value type is intended to render graphics that have been authored using the link:https://vega.github.io/vega-lite/[Vega-Lite] grammar.

A common use case is to render dashboards and other simple graphics.


[NOTE]
====
Although properties of this type can be edited, the xref:vw::about.adoc[Wicket viewer] does not provide any specialized authoring environment.
It is therefore most suitable for read-only values.
====

== Setup

=== Dependency Management

In your application's top level `pom.xml`, add a dependency for this module's own bill of materials (BOM):

[source,xml,subs="attributes+"]
.pom.xml
----
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.valuetypes</groupId>
            <artifactId>causeway-valuetypes-vega</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>{page-causewayreleaseversion}</version>
        </dependency>
    </dependencies>
</dependencyManagement>
----

=== Dependencies / Imports

In those modules where there are domain objects that use the `Vega` value type:

* add this dependency:
+
[source,xml,subs="attributes+"]
.pom.xml
----
<dependencies>
    <dependency>
        <groupId>org.apache.causeway.valuetypes</groupId>
        <artifactId>causeway-valuetypes-vega-applib</artifactId>
    </dependency>
</dependencies>
----

* and `@Import` this module:
+
[source,java]
.MyModule.java
----
@Configuration
@Import({
    CausewayModuleValVegaApplib.class,
    // ...
})
public class MyModule { ... }
----

In addition, in the webapp module of your application, add the following dependencies:

* for the Wicket viewer:
+
[source,xml]
.pom.xml
----
<dependency>
    <groupId>org.apache.causeway.valuetypes</groupId>
    <artifactId>causeway-valuetypes-vega-ui-wkt</artifactId>
</dependency>
----

* and for persistence:
+
[source,xml]
.pom.xml
----
<dependency>
    <groupId>org.apache.causeway.valuetypes</groupId>
    <artifactId>causeway-valuetypes-vega-xxx</artifactId>   <!--.-->
</dependency>
----
<.> where `xxx` is `jpa` (if using xref:pjpa::about.adoc[]) or `jdo` (if using xref:pjdo::about.adoc[]).

And in your application's xref:userguide::modules.adoc#appmanifest[App Manifest], import the extension's implementation module:

[source,java]
.AppManifest.java
----
@Configuration
@Import({
        CausewayModuleValVegaUiWkt.class,
        CausewayModuleValVegaPersistenceXxx.class,  <!--.-->
        ...
})
public class AppManifest {
}
----
<.> where `Xxx` is `Jpa` (if using xref:pjpa::about.adoc[]) or `Jdo` (if using xref:pjdo::about.adoc[]).


== Usage

The property can be declared and used in both entities and view models.
If declared in an entity, then it should most likely be mapped to a CLOB:

* if declared in an xref:pjpa::[JPA] entity:
+
[source,java]
----
@Property
@PropertyLayout
@Column(nullable = false) @Lob @Basic(fetch=FetchType.LAZY) // <.>
@Getter @Setter
private Vega helpText;
----
<.> maps to a (c)lob

* if declared in an xref:pjdo::[JDO] entity:
+
[source,java]
----
@Property
@PropertyLayout
@Column(allowsNull = "false", jdbcType = "CLOB")        // <.>
@Getter @Setter
private Vega helpText;
----
<.> maps to a CLOB

* if declared in a JAXB view model:
+
[source,java]
----
@Property
@PropertyLayout
@XmlElement(required = true)
@Getter @Setter
private Vega helpText;
----


