Project

General

Profile

« Previous | Next » 

Revision 54115

remoed deprecated methods to retrieve the first harvest date from the workflow logger db

View differences:

modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/dsm/dao/MongoLoggerClientImpl.java
126 126
		return Instant.parse(startDate.replaceAll("\\+.*", "Z"));
127 127
	}
128 128

  
129
	@Override
130
	@Deprecated
131
	@Cacheable("dsm-firstharvestdate-cache")
132
	public String firstHarvestDate(final String dsId) throws DsmException {
133
		log.warn(String.format("firstHarvestDate(dsId = %s): not using cache", dsId));
134
		final Bson query = queryForAggregationHistory(dsId, "collect");
135
		try {
136
			final Optional<AggregationInfo> first = Utils.stream(getCollection().find(query)
137
					.projection(fields)
138
					.sort(dbo("system:startHumanDate", 1))
139
					.limit(1)
140
					.iterator())
141
					.map(getMapper())
142
					.findFirst();
143

  
144
			return first.isPresent() ? first.get().getDate() : null;
145
		} catch (Throwable e) {
146
			throw new DsmException(HttpStatus.SC_INTERNAL_SERVER_ERROR, String.format("error reading first harvesting date", dsId), e);
147
		}
148
	}
149

  
150 129
	private Instant asInstant(final AggregationInfo a) {
151 130
		return Instant.parse(a.getDate() + "T00:00:00Z");
152 131
	}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/dsm/dao/MongoLoggerClient.java
9 9

  
10 10
	List<AggregationInfo> getAggregationHistory(final String dsId) throws DsmException;
11 11

  
12
	@Deprecated
13
	String firstHarvestDate(final String dsId) throws DsmException;
14

  
15 12
	void dropCache();
16 13

  
17 14
}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/dsm/DsmCore.java
306 306
		return dsInfo;
307 307
	}
308 308

  
309
	@Deprecated
310
	private void getFirstHarvestingDate(final String dsId,
311
			final CountDownLatch outerLatch,
312
			final Queue<Throwable> errors,
313
			final DatasourceInfo dsInfo) {
314
		Futures.addCallback(
315
				executor.submit(() -> mongoLoggerClient.firstHarvestDate(dsId)),
316
				new FutureCallback<String>() {
317
					@Override
318
					public void onSuccess(@Nullable final String firstHarvestDate) {
319
						dsInfo.setFirstHarvestDate(firstHarvestDate);
320
						outerLatch.countDown();
321
					}
322

  
323
					@Override
324
					public void onFailure(final Throwable e) {
325
						log.error(ExceptionUtils.getStackTrace(e));
326
						errors.offer(e);
327
						outerLatch.countDown();
328
					}
329
				}, executor);
330
	}
331

  
332 309
	private void getAggregationHistory(final String dsId,
333 310
			final CountDownLatch outerLatch,
334 311
			final Queue<Throwable> errors,
modules/dnet-openaire-exporter/trunk/src/main/resources/dnet_dsm.sql
1
--
2
-- PostgreSQL database dump
3
--
4 1

  
5
-- Dumped from database version 9.4.1
6
-- Dumped by pg_dump version 9.6.2
7

  
8
SET statement_timeout = 0;
9
SET lock_timeout = 0;
10
SET client_encoding = 'UTF8';
11
SET standard_conforming_strings = on;
12
SET check_function_bodies = false;
13
SET client_min_messages = warning;
14
SET row_security = off;
15

  
16
--
17
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: 
18
--
19

  
20
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
21

  
22

  
23
SET search_path = public, pg_catalog;
24

  
25
SET default_tablespace = '';
26

  
27
SET default_with_oids = false;
28

  
29
--
30
-- Name: dsm_api; Type: TABLE; Schema: public; Owner: dnet
31
--
32

  
33 2
CREATE TABLE dsm_api (
34
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
35 3
    id character varying(255) NOT NULL,
36 4
    protocol character varying(255),
37 5
    datasource character varying(255),
......
40 8
    removable boolean DEFAULT false,
41 9
    typology character varying(255) DEFAULT 'UNKNOWN'::character varying,
42 10
    compatibility character varying(255) DEFAULT 'UNKNOWN'::character varying,
43
    compatibility_override character varying(255) DEFAULT null,
44 11
    metadata_identifier_path character varying(512) DEFAULT NULL::character varying,
45 12
    last_collection_total integer,
46 13
    last_collection_date timestamp without time zone,
......
52 19
    last_download_date timestamp without time zone,
53 20
    last_download_objid character varying(255) DEFAULT NULL::character varying,
54 21
    last_validation_job character varying(255) DEFAULT NULL::character varying,
55
    baseurl text
22
    baseurl text,
23
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
24
    compatibility_override character varying(255) DEFAULT NULL::character varying
56 25
);
57 26

  
58 27

  
59
ALTER TABLE dsm_api OWNER TO dnetapi;
60
ALTER TABLE ONLY dsm_api ADD CONSTRAINT dsm_api_pkey PRIMARY KEY (id);
61
ALTER TABLE ONLY dsm_api ADD CONSTRAINT dsm_api_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
28
ALTER TABLE public.dsm_api OWNER TO dnetapi;
62 29

  
63
--
64
-- Name: dsm_apiparams; Type: TABLE; Schema: public; Owner: dnet
65
--
66 30

  
67
CREATE TABLE dsm_apiparams (
68
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
69
    param character varying(255) NOT NULL,
70
    value character varying(255) DEFAULT ''::character varying NOT NULL,
71
    api character varying(255) NOT NULL
72
);
73

  
74

  
75
ALTER TABLE dsm_apiparams OWNER TO dnetapi;
76
ALTER TABLE ONLY dsm_apiparams ADD CONSTRAINT dsm_apicollection_pkey PRIMARY KEY (api, param);
77
ALTER TABLE ONLY dsm_apiparams ADD CONSTRAINT dsm_apicollections_api_fkey FOREIGN KEY (api) REFERENCES dsm_api(id);
78

  
79

  
80

  
81
--
82
-- Name: dsm_datasource_organization; Type: TABLE; Schema: public; Owner: dnet
83
--
84

  
85 31
CREATE TABLE dsm_datasource_organization (
86
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
87 32
    datasource character varying(255) NOT NULL,
88
    organization character varying(255) NOT NULL
33
    organization character varying(255) NOT NULL,
34
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
89 35
);
90 36

  
91 37

  
92
ALTER TABLE dsm_datasource_organization OWNER TO dnet;
93
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_organization_datasource_pkey PRIMARY KEY (datasource, organization);
94
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_datasource_organization_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
95
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_datasource_organization_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id) ON DELETE CASCADE;
38
ALTER TABLE public.dsm_datasource_organization OWNER TO dnetapi;
96 39

  
97 40
--
98
-- Name: dsm_datasourcepids; Type: TABLE; Schema: public; Owner: dnet
41
-- Name: dsm_datasources; Type: TABLE; Schema: public; Owner: dnetapi; Tablespace:
99 42
--
100 43

  
101
CREATE TABLE dsm_datasourcepids (
102
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
103
    datasource character varying(255) NOT NULL,
104
    pid character varying(255) NOT NULL
105
);
106

  
107

  
108
ALTER TABLE dsm_datasourcepids OWNER TO dnet;
109
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_pkey PRIMARY KEY (datasource, pid);
110
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
111
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
112

  
113

  
114
--
115
-- Name: dsm_datasources; Type: TABLE; Schema: public; Owner: dnet
116
--
117

  
118 44
CREATE TABLE dsm_datasources (
119
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
120 45
    id character varying(255) NOT NULL,
121 46
    officialname character varying(512) NOT NULL,
122 47
    englishname character varying(512),
......
127 52
    longitude double precision DEFAULT 0.0,
128 53
    timezone character varying(10) DEFAULT '0.0'::character varying,
129 54
    namespaceprefix character(12) NOT NULL,
130
    languages text DEFAULT ARRAY[]::character varying[],
55
    languages text,
131 56
    od_contenttypes text,
132 57
    collectedfrom character varying(255),
133 58
    dateofvalidation date,
......
135 60
    optional2 character varying(255),
136 61
    typology character varying(255) NOT NULL,
137 62
    provenanceaction character varying(255) DEFAULT 'UNKNOWN'::character varying,
138
    dateofcollection date DEFAULT ('now'::text)::date,
63
    dateofcollection date DEFAULT ('now'::text)::date NOT NULL,
139 64
    platform character varying(255),
140 65
    activationid character varying(255),
141 66
    description text,
......
153 78
    qualitymanagementkind character varying(32),
154 79
    pidsystems text,
155 80
    certificates text,
156
    aggregator character varying(64) DEFAULT 'OPENAIRE'::character varying,
81
    aggregator character varying(64) DEFAULT 'OPENAIRE'::character varying NOT NULL,
157 82
    issn character varying(20),
158 83
    eissn character varying(20),
159 84
    lissn character varying(20),
160 85
    registeredby character varying(255),
86
    subjects text,
87
    managed boolean DEFAULT false,
161 88
    registrationdate date,
162
    subjects text DEFAULT ARRAY[]::character varying[],
163
    managed boolean DEFAULT false
89
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
164 90
);
165 91

  
166
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_namespaceprefix_key UNIQUE (namespaceprefix);
167
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_pkey PRIMARY KEY (id);
168
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
169 92

  
170
CREATE INDEX dsm_datasources_id_idx ON dsm_datasources (id);
171
CREATE INDEX dsm_datasources_contactemail_idx ON dsm_datasources (contactemail);
172
CREATE INDEX dsm_datasources_englishname_idx ON dsm_datasources (englishname);
173
CREATE INDEX dsm_datasources_officialname_idx ON dsm_datasources (officialname);
93
ALTER TABLE public.dsm_datasources OWNER TO dnetapi;
174 94

  
175
ALTER TABLE dsm_datasources OWNER TO dnetapi;
95
--
96
-- Name: dsm_organizations; Type: TABLE; Schema: public; Owner: dnetapi; Tablespace:
97
--
176 98

  
99
CREATE TABLE dsm_organizations (
100
    id character varying(255) NOT NULL,
101
    legalshortname character varying(255),
102
    legalname character varying(255),
103
    websiteurl text,
104
    logourl character varying(255),
105
    ec_legalbody boolean DEFAULT false,
106
    ec_legalperson boolean DEFAULT false,
107
    ec_nonprofit boolean DEFAULT false,
108
    ec_researchorganization boolean DEFAULT false,
109
    ec_highereducation boolean DEFAULT false,
110
    ec_internationalorganizationeurinterests boolean DEFAULT false,
111
    ec_internationalorganization boolean DEFAULT false,
112
    ec_enterprise boolean DEFAULT false,
113
    ec_smevalidated boolean DEFAULT false,
114
    ec_nutscode boolean DEFAULT false,
115
    country character varying(255),
116
    collectedfrom character varying(255),
117
    optional1 character varying(255),
118
    optional2 character varying(255),
119
    dateofcollection date DEFAULT ('now'::text)::date NOT NULL,
120
    provenanceaction character varying(255) DEFAULT 'UNKNOWN'::character varying,
121
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
122
    lastupdate date DEFAULT ('now'::text)::date NOT NULL,
123
    trust double precision DEFAULT 0.9
124
);
125

  
126

  
127
ALTER TABLE public.dsm_organizations OWNER TO dnetapi;
128

  
177 129
--
178
-- Name: dsm_identities; Type: TABLE; Schema: public; Owner: dnet
130
-- Name: browse_countries; Type: VIEW; Schema: public; Owner: dnet
179 131
--
180 132

  
133
CREATE VIEW browse_countries AS
134
 SELECT o.country AS term,
135
    count(*) AS total
136
   FROM (((dsm_api a
137
     LEFT JOIN dsm_datasources d ON (((a.datasource)::text = (d.id)::text)))
138
     LEFT JOIN dsm_datasource_organization dao ON (((d.id)::text = (dao.datasource)::text)))
139
     LEFT JOIN dsm_organizations o ON (((dao.organization)::text = (o.id)::text)))
140
  GROUP BY o.country
141
  ORDER BY count(*) DESC;
142

  
143

  
144
ALTER TABLE public.browse_countries OWNER TO dnet;
145

  
146

  
147

  
148
CREATE TABLE dsm_apiparams (
149
    param character varying(255) NOT NULL,
150
    value text DEFAULT ''::character varying NOT NULL,
151
    api character varying(255) NOT NULL,
152
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
153
);
154

  
155

  
156
ALTER TABLE public.dsm_apiparams OWNER TO dnetapi;
157

  
158
--
159
-- Name: dsm_datasource_api; Type: VIEW; Schema: public; Owner: dnet
160
--
161

  
162
CREATE VIEW dsm_datasource_api AS
163
 SELECT row_number() OVER (ORDER BY a.id) AS rowid,
164
    d.id,
165
    d.officialname,
166
    d.englishname,
167
    d.websiteurl,
168
    d.logourl,
169
    d.contactemail,
170
    d.latitude,
171
    d.longitude,
172
    d.timezone,
173
    d.namespaceprefix,
174
    d.languages,
175
    d.od_contenttypes,
176
    d.collectedfrom,
177
    d.dateofvalidation,
178
    d.optional1,
179
    d.optional2,
180
    d.typology,
181
    d.provenanceaction,
182
    d.dateofcollection,
183
    d.platform,
184
    d.activationid,
185
    d.description,
186
    d.releasestartdate,
187
    d.releaseenddate,
188
    d.missionstatementurl,
189
    d.dataprovider,
190
    d.serviceprovider,
191
    d.databaseaccesstype,
192
    d.datauploadtype,
193
    d.databaseaccessrestriction,
194
    d.datauploadrestriction,
195
    d.versioning,
196
    d.citationguidelineurl,
197
    d.qualitymanagementkind,
198
    d.pidsystems,
199
    d.certificates,
200
    d.aggregator,
201
    d.issn,
202
    d.eissn,
203
    d.lissn,
204
    d.registeredby,
205
    d.subjects,
206
    d.managed,
207
    a.protocol,
208
    a.contentdescription,
209
    a.active,
210
    a.removable,
211
    a.typology AS apitypology,
212
    a.compatibility,
213
    a.metadata_identifier_path,
214
    a.baseurl
215
   FROM (dsm_datasources d
216
     LEFT JOIN dsm_api a ON (((d.id)::text = (a.datasource)::text)));
217

  
218

  
219
ALTER TABLE public.dsm_datasource_api OWNER TO dnet;
220

  
221
--
222
-- Name: dsm_datasourcepids; Type: TABLE; Schema: public; Owner: dnetapi; Tablespace:
223
--
224

  
225
CREATE TABLE dsm_datasourcepids (
226
    datasource character varying(255) NOT NULL,
227
    pid character varying(255) NOT NULL,
228
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
229
);
230

  
231

  
232
ALTER TABLE public.dsm_datasourcepids OWNER TO dnetapi;
233

  
234
--
235
-- Name: dsm_identities; Type: TABLE; Schema: public; Owner: dnetapi; Tablespace:
236
--
237

  
181 238
CREATE TABLE dsm_identities (
182
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
183 239
    pid character varying(255) NOT NULL,
184
    issuertype character varying(255)
240
    issuertype character varying(255),
241
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
185 242
);
186 243

  
187 244

  
188
ALTER TABLE dsm_identities OWNER TO dnetapi;
189
ALTER TABLE ONLY dsm_identities ADD CONSTRAINT dsm_identities_pkey PRIMARY KEY (pid);
245
ALTER TABLE public.dsm_identities OWNER TO dnetapi;
190 246

  
191

  
192 247
--
193
-- Name: dsm_organizationpids; Type: TABLE; Schema: public; Owner: dnet
248
-- Name: dsm_organizationpids; Type: TABLE; Schema: public; Owner: dnetapi; Tablespace:
194 249
--
195 250

  
196 251
CREATE TABLE dsm_organizationpids (
197
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
198 252
    organization character varying(255) NOT NULL,
199
    pid character varying(255) NOT NULL
253
    pid character varying(255) NOT NULL,
254
    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
200 255
);
201 256

  
202
ALTER TABLE dsm_organizationpids OWNER TO dnet;
203
ALTER TABLE ONLY dsm_organizationpids ADD CONSTRAINT dsm_organizationpids_pkey PRIMARY KEY (organization, pid);
204
ALTER TABLE ONLY dsm_organizationpids ADD CONSTRAINT dsm_organizationpids_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id);
205 257

  
258
ALTER TABLE public.dsm_organizationpids OWNER TO dnetapi;
206 259

  
207 260
--
208
-- Name: dsm_organizations; Type: TABLE; Schema: public; Owner: dnet
261
-- Name: funder_identity; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
209 262
--
210 263

  
211
CREATE TABLE dsm_organizations (
212
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
264
CREATE TABLE funder_identity (
265
    funder character varying(255),
266
    pid character varying(255)
267
);
268

  
269

  
270
ALTER TABLE public.funder_identity OWNER TO dnet;
271

  
272
--
273
-- Name: funders; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
274
--
275

  
276
CREATE TABLE funders (
213 277
    id character varying(255) NOT NULL,
214
    legalshortname character varying(255),
215
    legalname character varying(255),
278
    name character varying(255),
279
    shortname character varying(255),
280
    jurisdiction character varying(255),
216 281
    websiteurl text,
217
    logourl character varying(255),
218
    country character varying(255),
219
    collectedfrom character varying(255),
220
    optional1 character varying(255),
221
    optional2 character varying(255),
222
    dateofcollection date DEFAULT ('now'::text)::date NOT NULL,
223
    provenanceaction character varying(255) DEFAULT 'UNKNOWN'::character varying
282
    policy character varying(255),
283
    registrationdate date DEFAULT ('now'::text)::date NOT NULL,
284
    lastupdatedate date
224 285
);
225 286

  
226 287

  
227
ALTER TABLE dsm_organizations OWNER TO dnetapi;
228
ALTER TABLE ONLY dsm_organizations ADD CONSTRAINT dsm_organizations_pkey PRIMARY KEY (id);
229
ALTER TABLE ONLY dsm_organizations ADD CONSTRAINT dsm_organizations_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
288
ALTER TABLE public.funders OWNER TO dnet;
230 289

  
231
CREATE INDEX dsm_organizations_country_idx ON dsm_organizations (country);
290
--
291
-- Name: fundingpaths; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
292
--
232 293

  
233 294

  
234
CREATE TABLE funders (
235
  id character varying(255),
236
  name character varying(255),
237
  shortname character varying(255),
238
  jurisdiction character varying(255),
239
  websiteurl text,
240
  policy character varying(255),
241
  registrationdate date DEFAULT ('now'::text)::date NOT NULL,
242
  lastupdatedate date
243
);
244 295

  
245
GRANT ALL ON funders to dnetapi ;
246
ALTER TABLE ONLY funders ADD CONSTRAINT funders_pkey PRIMARY KEY (id);
247 296

  
248
CREATE TABLE funder_identity (
249
  funder character varying(255),
250
  pid character varying(255)
251
);
252 297

  
253
GRANT ALL ON funder_identity to dnetapi ;
254
ALTER TABLE ONLY funder_identity ADD CONSTRAINT funder_identity_funder_fkey FOREIGN KEY (funder) REFERENCES funders(id);
255
ALTER TABLE ONLY funder_identity ADD CONSTRAINT funder_identity_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
256 298

  
257
ALTER TABLE fundingpaths ADD COLUMN funderid varchar(255) ;
258
ALTER TABLE fundingpaths ADD CONSTRAINT fundingpaths_funderid_fkey FOREIGN KEY (funderid) REFERENCES funders(id);
259 299

  
300

  
301

  
302

  
303

  
304

  
305

  
306

  
260 307
--
261
-- Name: search_api; Type: VIEW; Schema: public; Owner: dnet
308
-- Name: project_organization; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
262 309
--
263 310

  
264
CREATE VIEW search_api AS
265
 SELECT a.id,
266
    a.compatibility,
267
    a.protocol,
268
    a.active,
269
    a.last_aggregation_date,
270
    a.last_aggregation_total,
271
    d.id AS repoid,
272
    d.officialname,
273
    d.englishname,
274
    d.namespaceprefix,
275
    (array_agg(DISTINCT o.country))[1] AS country,
276
    (array_agg(DISTINCT o.legalname))[1] AS organization
277
   FROM (((dsm_api a
278
     LEFT JOIN dsm_datasources d ON (((a.datasource)::text = (d.id)::text)))
279
     LEFT JOIN dsm_datasource_organization dor ON (((d.id)::text = (dor.datasource)::text)))
280
     LEFT JOIN dsm_organizations o ON (((dor.organization)::text = (o.id)::text)))
281
  GROUP BY a.id, a.compatibility, a.protocol, a.active, a.last_aggregation_date, a.last_aggregation_total, d.id, d.officialname, d.englishname, d.namespaceprefix;
311
--CREATE TABLE project_organization (
312
--    participantnumber integer,
313
--    project character varying(255) NOT NULL,
314
--    resporganization character varying(255) NOT NULL,
315
--    semanticclass character varying(255) DEFAULT 'UNKNOWN'::character varying,
316
--    trust double precision DEFAULT 0.9,
317
--    _dnet_resource_identifier_ character varying(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text))
318
--);
282 319

  
283 320

  
284
ALTER TABLE search_api OWNER TO dnetapi;
321
--ALTER TABLE public.project_organization OWNER TO dnet;
285 322

  
286
CREATE VIEW browse_activation AS
287
 SELECT dsm_api.active::text AS term,
288
    count(*) AS total
289
   FROM dsm_api
290
  GROUP BY dsm_api.active
291
  ORDER BY count(*) DESC;
292 323

  
293
CREATE VIEW browse_compatibility AS
294
 SELECT a.compatibility AS term,
295
    count(*) AS total
296
   FROM dsm_api a
297
  GROUP BY a.compatibility
298
  ORDER BY count(*) DESC;
299 324

  
300 325

  
326
--
327
-- Name: dsm_api_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
328
--
301 329

  
302
CREATE VIEW browse_countries AS
303
 SELECT o.country AS term,
304
    count(*) AS total
305
   FROM dsm_api a
306
     LEFT JOIN dsm_datasources d ON a.datasource::text = d.id::text
307
     LEFT JOIN dsm_datasource_organization dao ON d.id::text = dao.datasource::text
308
     LEFT JOIN dsm_organizations o ON dao.organization::text = o.id::text
309
  GROUP BY o.country
310
  ORDER BY count(*) DESC;
330
ALTER TABLE ONLY dsm_api
331
    ADD CONSTRAINT dsm_api_pkey PRIMARY KEY (id);
311 332

  
312 333

  
313
CREATE VIEW browse_protocols AS
314
 SELECT a.protocol AS term,
315
    count(*) AS total
316
   FROM dsm_api a
317
  GROUP BY a.protocol
318
  ORDER BY count(*) DESC;
334
--
335
-- Name: dsm_apicollection_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
336
--
319 337

  
320
CREATE VIEW browse_typologies AS
321
 SELECT a.typology AS term,
322
    count(*) AS total
323
   FROM dsm_api a
324
  GROUP BY a.typology
325
  ORDER BY count(*) DESC;
338
ALTER TABLE ONLY dsm_apiparams
339
    ADD CONSTRAINT dsm_apicollection_pkey PRIMARY KEY (api, param);
326 340

  
327
CREATE OR REPLACE VIEW dsm_datasource_api AS (
328
  SELECT
329
    row_number() OVER (ORDER BY a.id) AS rowid,
330
    d.officialname,
331
    d.englishname,
332
    d.websiteurl,
333
    d.contactemail,
334
    d.registeredby,
335
    d.typology,
336
    d.platform,
337
    d.managed,
338
    a.protocol,
339
    a.contentdescription,
340
    a.active,
341
    a.removable,
342
    a.typology AS apitypology,
343
    a.compatibility,
344
    a.baseurl
345
  FROM dsm_datasources d LEFT OUTER JOIN dsm_api a ON (d.id = a.datasource));
346
grant select on dsm_datasource_api to dnetapi ;
341

  
342
--
343
-- Name: dsm_datasourcepids_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
344
--
345

  
346
ALTER TABLE ONLY dsm_datasourcepids
347
    ADD CONSTRAINT dsm_datasourcepids_pkey PRIMARY KEY (datasource, pid);
348

  
349

  
350
--
351
-- Name: dsm_datasources_namespaceprefix_key; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
352
--
353

  
354
ALTER TABLE ONLY dsm_datasources
355
    ADD CONSTRAINT dsm_datasources_namespaceprefix_key UNIQUE (namespaceprefix);
356

  
357

  
358
--
359
-- Name: dsm_datasources_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
360
--
361

  
362
ALTER TABLE ONLY dsm_datasources
363
    ADD CONSTRAINT dsm_datasources_pkey PRIMARY KEY (id);
364

  
365

  
366
--
367
-- Name: dsm_identities_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
368
--
369

  
370
ALTER TABLE ONLY dsm_identities
371
    ADD CONSTRAINT dsm_identities_pkey PRIMARY KEY (pid);
372

  
373

  
374
--
375
-- Name: dsm_organization_datasource_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
376
--
377

  
378
ALTER TABLE ONLY dsm_datasource_organization
379
    ADD CONSTRAINT dsm_organization_datasource_pkey PRIMARY KEY (datasource, organization);
380

  
381

  
382
--
383
-- Name: dsm_organizationpids_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
384
--
385

  
386
ALTER TABLE ONLY dsm_organizationpids
387
    ADD CONSTRAINT dsm_organizationpids_pkey PRIMARY KEY (organization, pid);
388

  
389

  
390
--
391
-- Name: dsm_organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: dnetapi; Tablespace:
392
--
393

  
394
ALTER TABLE ONLY dsm_organizations
395
    ADD CONSTRAINT dsm_organizations_pkey PRIMARY KEY (id);
396

  
397

  
398

  
399

  
400

  
401

  
402
--
403
-- Name: dsm_datasources_contactemail_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
404
--
405

  
406
CREATE INDEX dsm_datasources_contactemail_idx ON dsm_datasources USING btree (contactemail);
407

  
408

  
409
--
410
-- Name: dsm_datasources_englishname_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
411
--
412

  
413
CREATE INDEX dsm_datasources_englishname_idx ON dsm_datasources USING btree (englishname);
414

  
415

  
416
--
417
-- Name: dsm_datasources_managed_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
418
--
419

  
420
CREATE INDEX dsm_datasources_managed_idx ON dsm_datasources USING btree (managed);
421

  
422

  
423
--
424
-- Name: dsm_datasources_officialname_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
425
--
426

  
427
CREATE INDEX dsm_datasources_officialname_idx ON dsm_datasources USING btree (officialname);
428

  
429

  
430
--
431
-- Name: dsm_datasources_registeredby_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
432
--
433

  
434
CREATE INDEX dsm_datasources_registeredby_idx ON dsm_datasources USING btree (registeredby);
435

  
436

  
437
--
438
-- Name: dsm_organizations_country_idx; Type: INDEX; Schema: public; Owner: dnetapi; Tablespace:
439
--
440

  
441
CREATE INDEX dsm_organizations_country_idx ON dsm_organizations USING btree (country);
442

  
443

  
444

  
445

  
446

  
447

  
448

  
449

  
450
ALTER TABLE ONLY dsm_api
451
    ADD CONSTRAINT dsm_api_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id) ON DELETE CASCADE;
452

  
453

  
454
--
455
-- Name: dsm_apicollections_api_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
456
--
457

  
458
ALTER TABLE ONLY dsm_apiparams
459
    ADD CONSTRAINT dsm_apicollections_api_fkey FOREIGN KEY (api) REFERENCES dsm_api(id);
460

  
461

  
462
--
463
-- Name: dsm_datasource_organization_datasource_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
464
--
465

  
466
ALTER TABLE ONLY dsm_datasource_organization
467
    ADD CONSTRAINT dsm_datasource_organization_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
468

  
469

  
470
--
471
-- Name: dsm_datasource_organization_organization_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
472
--
473

  
474
ALTER TABLE ONLY dsm_datasource_organization
475
    ADD CONSTRAINT dsm_datasource_organization_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id) ON DELETE CASCADE;
476

  
477

  
478
--
479
-- Name: dsm_datasourcepids_datasource_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
480
--
481

  
482
ALTER TABLE ONLY dsm_datasourcepids
483
    ADD CONSTRAINT dsm_datasourcepids_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
484

  
485

  
486
--
487
-- Name: dsm_datasourcepids_pid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
488
--
489

  
490
ALTER TABLE ONLY dsm_datasourcepids
491
    ADD CONSTRAINT dsm_datasourcepids_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
492

  
493

  
494
--
495
-- Name: dsm_datasources_collectedfrom_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
496
--
497

  
498
ALTER TABLE ONLY dsm_datasources
499
    ADD CONSTRAINT dsm_datasources_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
500

  
501

  
502
--
503
-- Name: dsm_organizationpids_organization_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
504
--
505

  
506
ALTER TABLE ONLY dsm_organizationpids
507
    ADD CONSTRAINT dsm_organizationpids_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id);
508

  
509

  
510
--
511
-- Name: dsm_organizationpids_pid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
512
--
513

  
514
ALTER TABLE ONLY dsm_organizationpids
515
    ADD CONSTRAINT dsm_organizationpids_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
516

  
517

  
518
--
519
-- Name: dsm_organizations_collectedfrom_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnetapi
520
--
521

  
522
ALTER TABLE ONLY dsm_organizations
523
    ADD CONSTRAINT dsm_organizations_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
524

  
525

  
526

  
527
REVOKE ALL ON SCHEMA public FROM PUBLIC;
528
REVOKE ALL ON SCHEMA public FROM postgres;
529
GRANT ALL ON SCHEMA public TO postgres;
530
GRANT ALL ON SCHEMA public TO PUBLIC;
531

  
532

  
533
REVOKE ALL ON TABLE browse_countries FROM PUBLIC;
534
REVOKE ALL ON TABLE browse_countries FROM dnet;
535
GRANT ALL ON TABLE browse_countries TO dnet;
536
GRANT ALL ON TABLE browse_countries TO dnetapi;
537

  
538

  
539
REVOKE ALL ON TABLE dsm_datasource_api FROM PUBLIC;
540
REVOKE ALL ON TABLE dsm_datasource_api FROM dnet;
541
GRANT ALL ON TABLE dsm_datasource_api TO dnet;
542
GRANT SELECT ON TABLE dsm_datasource_api TO dnetapi;
543

  
544

  

Also available in: Unified diff