diff --git a/.gitignore b/.gitignore index e773ec19..80086004 100644 --- a/.gitignore +++ b/.gitignore @@ -8,19 +8,19 @@ *~ .vscode .classpath -/*/.classpath -/*/*/.classpath +/**/.classpath .metadata -/*/.metadata -/*/*/.metadata +/**/.metadata .project +/**/.project .settings -/*/*/target -/*/target -/target -/*/*/build -/*/build -/build +/**/.settings +.factorypath +/**/.factorypath +target +/**/target +build +/**/build spark-warehouse /**/job-override.properties /**/*.log diff --git a/apps/dhp-broker-application/pom.xml b/apps/dhp-broker-application/pom.xml index d66ccc22..0b20d095 100644 --- a/apps/dhp-broker-application/pom.xml +++ b/apps/dhp-broker-application/pom.xml @@ -34,10 +34,10 @@ - + - com.h2database - h2 + org.postgresql + postgresql diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/objects/CurrentStatus.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/objects/CurrentStatus.java index f1d9e1a5..709cbe08 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/objects/CurrentStatus.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/controllers/objects/CurrentStatus.java @@ -16,7 +16,7 @@ import eu.dnetlib.lbs.properties.EmailProperties; public class CurrentStatus { @Autowired - private DatabaseProperties h2; + private DatabaseProperties db; @Autowired private ElasticSearchProperties elasticSearch; @@ -72,12 +72,12 @@ public class CurrentStatus { this.elasticSearch = elasticSearch; } - public DatabaseProperties getH2() { - return this.h2; + public DatabaseProperties getDb() { + return this.db; } - public void setH2(final DatabaseProperties h2) { - this.h2 = h2; + public void setDb(final DatabaseProperties db) { + this.db = db; } } diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/properties/DatabaseProperties.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/properties/DatabaseProperties.java index efc6d838..fd2f314a 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/properties/DatabaseProperties.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/properties/DatabaseProperties.java @@ -9,19 +9,9 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "lbs.database") public class DatabaseProperties { - @NotNull - private String driverName; @NotNull private String url; - public String getDriverName() { - return this.driverName; - } - - public void setDriverName(final String driverName) { - this.driverName = driverName; - } - public String getUrl() { return this.url; } diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/subscriptions/Subscription.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/subscriptions/Subscription.java index a47432f7..18906cf6 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/subscriptions/Subscription.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/subscriptions/Subscription.java @@ -24,7 +24,7 @@ public class Subscription { @Column(name = "subscriptionid") private String subscriptionId; - @Column(name = "subscriber", length = 4096, nullable = false) + @Column(name = "subscriber", nullable = false) private String subscriber; @Column(name = "topic", nullable = false) @@ -44,19 +44,19 @@ public class Subscription { @Column(name = "creationDate", nullable = false, columnDefinition = "timestamp default '2018-01-01 00:00:00'") private Date creationDate; - @Column(name = "conditions", length = 4096, nullable = true) + @Column(name = "conditions", nullable = true) private String conditions; public Subscription() {} public Subscription(final String subscriptionId, final String subscriber, final String topic, final NotificationFrequency frequency, - final NotificationMode mode, - final Date lastNotificationDate, final Date creationDate, final List conditions) { + final NotificationMode mode, + final Date lastNotificationDate, final Date creationDate, final List conditions) { this(subscriptionId, subscriber, topic, frequency, mode, lastNotificationDate, creationDate, new Gson().toJson(conditions)); } public Subscription(final String subscriptionId, final String subscriber, final String topic, final NotificationFrequency frequency, - final NotificationMode mode, final Date lastNotificationDate, final Date creationDate, final String conditions) { + final NotificationMode mode, final Date lastNotificationDate, final Date creationDate, final String conditions) { this.subscriptionId = subscriptionId; this.subscriber = subscriber; this.topic = topic; @@ -144,9 +144,11 @@ public class Subscription { return true; } else { final long diff = new Date().getTime() - s.getLastNotificationDate().getTime(); - if (((s.getFrequency() == NotificationFrequency.daily) && (diff >= TimeUnit.DAYS.toMillis(1))) || - ((s.getFrequency() == NotificationFrequency.weekly) && (diff >= TimeUnit.DAYS.toMillis(7))) || - ((s.getFrequency() == NotificationFrequency.monthly) && (diff >= TimeUnit.DAYS.toMillis(30)))) { return true; } + if (s.getFrequency() == NotificationFrequency.daily && diff >= TimeUnit.DAYS.toMillis(1) || + s.getFrequency() == NotificationFrequency.weekly && diff >= TimeUnit.DAYS.toMillis(7) || + s.getFrequency() == NotificationFrequency.monthly && diff >= TimeUnit.DAYS.toMillis(30)) { + return true; + } } return false; } diff --git a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/topics/TopicType.java b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/topics/TopicType.java index e536f79d..de9516c6 100644 --- a/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/topics/TopicType.java +++ b/apps/dhp-broker-application/src/main/java/eu/dnetlib/lbs/topics/TopicType.java @@ -28,16 +28,16 @@ public class TopicType { @Column(name = "name", nullable = false, unique = true) private String name; - @Column(name = "expression", length = 4096, unique = true, nullable = false) + @Column(name = "expression", unique = true, nullable = false) private String expression; - @Column(name = "regex", length = 4096, unique = true, nullable = false) + @Column(name = "regex", unique = true, nullable = false) private String regex; - @Column(name = "producerId", length = 4096) + @Column(name = "producerId") private String producerId; - @Column(name = "mapKeys", length = 4096) + @Column(name = "mapKeys") private String mapKeys; public TopicType() {} @@ -116,11 +116,11 @@ public class TopicType { final Predicate p = Pattern.compile(getRegex()).asPredicate(); final Set keys = getMapKeysAsSet(); return e -> e != null - && StringUtils.isNotBlank(e.getTopic()) - && p.test(e.getTopic()) - && (StringUtils.isBlank(TopicType.this.producerId) || - TopicType.this.producerId.equals(e.getProducerId())) - && e.getMap().keySet().containsAll(keys); + && StringUtils.isNotBlank(e.getTopic()) + && p.test(e.getTopic()) + && (StringUtils.isBlank(TopicType.this.producerId) || + TopicType.this.producerId.equals(e.getProducerId())) + && e.getMap().keySet().containsAll(keys); } } diff --git a/apps/dhp-broker-application/src/main/resources/application.properties b/apps/dhp-broker-application/src/main/resources/application.properties index 23686587..f571b6c1 100644 --- a/apps/dhp-broker-application/src/main/resources/application.properties +++ b/apps/dhp-broker-application/src/main/resources/application.properties @@ -1,14 +1,20 @@ spring.profiles.active = dev -spring.h2.console.enabled = true -spring.datasource.url = jdbc:h2:/tmp/lbs/prova -spring.datasource.username = lbs -spring.datasource.password = lbs -spring.datasource.driver-class-name = org.h2.Driver -spring.jpa.hibernate.ddl-auto = update -spring.jpa.database-platform = org.hibernate.dialect.H2Dialect +spring.datasource.url=jdbc:postgresql://localhost:5432/dnet_broker +spring.datasource.username= +spring.datasource.password= + +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect + +# Hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto = validate +spring.jpa.properties.hibernate.hbm2dll.extra_physical_table_types = MATERIALIZED VIEW +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true +spring.jpa.open-in-view = true +spring.jpa.properties.hibernate.show_sql = false +spring.jpa.properties.hibernate.use_sql_comments = false +spring.jpa.properties.hibernate.format_sql = false -lbs.database.driverName = ${spring.datasource.driver-class-name} lbs.database.url = ${spring.datasource.url} # for development server diff --git a/apps/dhp-broker-application/src/main/resources/config/mapping_es7.sh b/apps/dhp-broker-application/src/main/resources/config/mapping_es7.sh index eb851b8a..eb2841d6 100755 --- a/apps/dhp-broker-application/src/main/resources/config/mapping_es7.sh +++ b/apps/dhp-broker-application/src/main/resources/config/mapping_es7.sh @@ -54,19 +54,3 @@ curl -XPUT -H 'Content-Type: application/json' "$INDEXBASEURL/$NOTIFICATIONINDEX } } }' - -echo -echo -echo "Registering topic type: ENRICH//..." -curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" -echo -echo -echo "Registering topic type: ENRICH///..." -curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH_WITH_SUBFIELD&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E%2F%3Csubfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" -echo -echo -echo "Registering topic type: ADD/..." -curl "http://localhost:8080/api/topic-types/add" -d "name=ADD&expression=ADD%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" -echo -echo -echo diff --git a/apps/dhp-broker-application/src/main/resources/config/schema.sql b/apps/dhp-broker-application/src/main/resources/config/schema.sql new file mode 100644 index 00000000..a356c351 --- /dev/null +++ b/apps/dhp-broker-application/src/main/resources/config/schema.sql @@ -0,0 +1,28 @@ +CREATE TABLE subscriptions ( + subscriptionid text PRIMARY KEY, + conditions text, + creation_date timestamp without time zone DEFAULT '2018-01-01 00:00:00'::timestamp without time zone NOT NULL, + frequency text NOT NULL, + last_notification_date timestamp without time zone, + mode text NOT NULL, + subscriber text NOT NULL, + topic text NOT NULL +); + +CREATE TABLE topic_types ( + id text PRIMARY KEY, + name text UNIQUE NOT NULL, + expression text UNIQUE NOT NULL, + map_keys text, + producer_id text, + regex text UNIQUE NOT NULL +); + +-- curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" +INSERT INTO public.topic_types (id, name, expression, map_keys, producer_id, regex) VALUES ('tt-a739fa2b-fde0-4eb2-bcee-6e7f277347db', 'ENRICH', 'ENRICH//', 'targetDatasourceName', 'OpenAIRE', '^ENRICH\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$'); + +-- curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH_WITH_SUBFIELD&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E%2F%3Csubfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" +INSERT INTO public.topic_types (id, name, expression, map_keys, producer_id, regex) VALUES ('tt-93be0404-e7fb-43bb-9a0a-d317f418ed6d', 'ENRICH_WITH_SUBFIELD', 'ENRICH///', 'targetDatasourceName', 'OpenAIRE', '^ENRICH\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$'); + +-- curl "http://localhost:8080/api/topic-types/add" -d "name=ADD&expression=ADD%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName" +INSERT INTO public.topic_types (id, name, expression, map_keys, producer_id, regex) VALUES ('tt-80978da9-1859-47aa-9897-0a0c372365a1', 'ADD', 'ADD/', 'targetDatasourceName', 'OpenAIRE', '^ADD\/[a-zA-Z0-9._-]+$'); diff --git a/apps/dhp-broker-application/src/main/resources/static/html/subscriptions.html b/apps/dhp-broker-application/src/main/resources/static/html/subscriptions.html index 58aa4f37..73c8b55f 100644 --- a/apps/dhp-broker-application/src/main/resources/static/html/subscriptions.html +++ b/apps/dhp-broker-application/src/main/resources/static/html/subscriptions.html @@ -1,4 +1,4 @@ -

Subscriptions (H2 database)

+

Subscriptions (Postgres database)