replaced h2 with potgres

This commit is contained in:
Michele Artini 2020-07-23 15:34:53 +02:00
parent b98ff0f497
commit 02142f1d11
12 changed files with 84 additions and 77 deletions

20
.gitignore vendored
View File

@ -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

View File

@ -34,10 +34,10 @@
</exclusions>
</dependency>
<!-- H2 DB -->
<!-- Postgres -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- Gson -->

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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<MapCondition> conditions) {
final NotificationMode mode,
final Date lastNotificationDate, final Date creationDate, final List<MapCondition> 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;
}

View File

@ -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<String> p = Pattern.compile(getRegex()).asPredicate();
final Set<String> 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);
}
}

View File

@ -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

View File

@ -54,19 +54,3 @@ curl -XPUT -H 'Content-Type: application/json' "$INDEXBASEURL/$NOTIFICATIONINDEX
}
}
}'
echo
echo
echo "Registering topic type: ENRICH/<cond>/<field>..."
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/<cond>/<field>/<subfield>..."
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/<field>..."
curl "http://localhost:8080/api/topic-types/add" -d "name=ADD&expression=ADD%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName"
echo
echo
echo

View File

@ -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/<cond>/<field>', '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/<cond>/<field>/<subfield>', '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/<field>', 'targetDatasourceName', 'OpenAIRE', '^ADD\/[a-zA-Z0-9._-]+$');

View File

@ -1,4 +1,4 @@
<h3>Subscriptions (H2 database)</h3>
<h3>Subscriptions (Postgres database)</h3>
<form class="form-inline text-right" style="margin-top:40px; margin-bottom:20px">
<button class="btn btn-primary" data-target="#addSubscriptionModal" data-toggle="modal" ng-click="resetFormFields()">

View File

@ -149,14 +149,11 @@
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">H2 database</div>
<div class="panel-heading">Postgres database</div>
<table class="table">
<tr>
<th class="col-xs-4">path</th>
<td class="col-xs-8">{{summary.h2.url}}</td>
</tr><tr>
<th class="col-xs-4">driver</th>
<td class="col-xs-8">{{summary.h2.driverName}}</td>
<td class="col-xs-8">{{summary.db.url}}</td>
</tr>
</table>
</div>

View File

@ -200,7 +200,7 @@ CREATE VIEW organizations_simple_view AS SELECT
org.type,
org.city,
org.country,
array_agg(DISTINCT a.acronym) FILTER (WHERE a.acronym IS NOT NULL) AS acronyms
array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms
FROM
organizations org
LEFT OUTER JOIN acronyms a ON (org.id = a.id)
@ -215,7 +215,7 @@ CREATE VIEW users_view AS SELECT
u.email,
u.valid,
u.role,
array_agg(uc.country) FILTER (WHERE uc.country IS NOT NULL) AS countries
array_remove(array_agg(uc.country), NULL) AS countries
FROM
users u
LEFT OUTER JOIN user_countries uc ON (u.email = uc.email)