Project

General

Profile

« Previous | Next » 

Revision 50355

ui: overriding compliance

View differences:

LocalOpenaireDatasourceManager.java
52 52
	private static final Resource setManaged = new ClassPathResource(QUERY_BASEDIR + "setManaged.sql");
53 53
	private static final Resource setCompliance = new ClassPathResource(QUERY_BASEDIR + "setCompliance.sql");
54 54
	private static final Resource overrideCompliance = new ClassPathResource(QUERY_BASEDIR + "overrideCompliance.sql");
55
	private static final Resource resetCompliance = new ClassPathResource(QUERY_BASEDIR + "resetCompliance.sql");
55 56
	private static final Resource setLastCollectionInfo = new ClassPathResource(QUERY_BASEDIR + "setLastCollectionInfo.sql");
56 57
	private static final Resource setLastAggregationInfo = new ClassPathResource(QUERY_BASEDIR + "setLastAggregationInfo.sql");
57 58
	private static final Resource setLastDownloadInfo = new ClassPathResource(QUERY_BASEDIR + "setLastDownloadInfo.sql");
......
60 61

  
61 62
	private static final Log log = LogFactory.getLog(LocalOpenaireDatasourceManager.class);
62 63

  
64
	private static final String REPO_PROFILEID_SUFFIX = "_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=";
65

  
63 66
	@Override
64 67
	public List<SimpleDatasource> searchDatasourcesByType(final String type) throws DsmException {
65 68
		return datasourceManagerClients.searchSQL(searchDsByType, ImmutableMap.of("type", type))
......
114 117

  
115 118
	@Override
116 119
	public void deleteDs(final String dsId) throws DsmException {
117
		datasourceManagerClients.updateSQL(dsId, deleteDs, AfterSqlUpdate.DELETE_DS_PROFILE, ImmutableMap.of("dsId", dsId));
120
		datasourceManagerClients.updateSQL(fixDsId(dsId), deleteDs, AfterSqlUpdate.DELETE_DS_PROFILE, ImmutableMap.of("dsId", dsId));
118 121
	}
119 122

  
120 123
	@Override
121 124
	public Datasource<Organization<?>, Identity> getDs(final String dsId) throws DsmException {
122
		return datasourceManagerClients.getDatasourceById(dsId);
125
		return datasourceManagerClients.getDatasourceById(fixDsId(dsId));
123 126
	}
124 127

  
125 128
	@Override
......
129 132

  
130 133
	@Override
131 134
	public List<Api<ApiParam>> getApis(final String dsId) throws DsmException {
132
		return datasourceManagerClients.getApis(dsId);
135
		return datasourceManagerClients.getApis(fixDsId(dsId));
133 136
	}
134 137

  
135 138
	@Override
136 139
	public void setManaged(final String dsId, final boolean managed) throws DsmException {
140
		final String id = fixDsId(dsId);
141

  
137 142
		final Map<String, Object> params = new HashMap<>();
138 143
		params.put("managed", managed);
139
		params.put("dsId", dsId);
144
		params.put("dsId", id);
140 145

  
141
		datasourceManagerClients.updateSQL(dsId, setManaged, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
146
		datasourceManagerClients.updateSQL(id, setManaged, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
142 147

  
143 148
	}
144 149

  
145 150
	@Override
146 151
	public boolean isManaged(final String dsId) throws DsmException {
147 152
		final String q = "SELECT * from dsm_datasources WHERE id = :dsId AND managed = true";
148
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", dsId)).isEmpty();
153
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", fixDsId(dsId))).isEmpty();
149 154
	}
150 155

  
151 156
	@Override
152 157
	public void setActive(final String dsId, final String apiId, final boolean active) throws DsmException {
158
		final String id = fixDsId(dsId);
159

  
153 160
		final Map<String, Object> params = new HashMap<>();
154 161
		params.put("active", active);
155 162
		params.put("apiId", apiId);
156
		params.put("dsId", dsId);
163
		params.put("dsId", id);
157 164

  
158
		datasourceManagerClients.updateSQL(dsId, setActive, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
165
		datasourceManagerClients.updateSQL(id, setActive, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
159 166
		if (!active) {
160
			setLastCollectionInfo(dsId, apiId, null, null, null);
161
			setLastAggregationInfo(dsId, apiId, null, null, null);
162
			setLastDownloadInfo(dsId, apiId, null, null, null);
167
			setLastCollectionInfo(id, apiId, null, null, null);
168
			setLastAggregationInfo(id, apiId, null, null, null);
169
			setLastDownloadInfo(id, apiId, null, null, null);
163 170
		}
164 171
	}
165 172

  
166 173
	@Override
167 174
	public boolean isActive(final String dsId, final String apiId) throws DsmException {
168 175
		final String q = "SELECT * from dsm_api WHERE id = :apiId AND datasource = :dsId AND active = true";
169
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", dsId, "apiId", apiId)).isEmpty();
176
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", fixDsId(dsId), "apiId", apiId)).isEmpty();
170 177
	}
171 178

  
172 179
	@Override
173 180
	public boolean isRemovable(final String dsId, final String apiId) throws DsmException {
174 181
		final String q = "SELECT * from dsm_api WHERE id = :apiId AND datasource = :dsId AND active != true AND removable = true";
175
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", dsId, "apiId", apiId)).isEmpty();
182
		return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", fixDsId(dsId), "apiId", apiId)).isEmpty();
176 183
	}
177 184

  
178 185
	@Override
179 186
	public void updateCompliance(final String dsId, final String apiId, final String level, final boolean override) throws DsmException {
180
		final Map<String, Object> params = ImmutableMap.of("level", level, "apiId", apiId, "dsId", dsId);
181
		datasourceManagerClients.updateSQL(dsId, override ? overrideCompliance : setCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
187
		final String id = fixDsId(dsId);
188

  
189
		if (!override) {
190
			datasourceManagerClients.updateSQL(id, setCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE,
191
					ImmutableMap.of("level", level, "apiId", apiId, "dsId", id));
192
		} else if (level != null) {
193
			datasourceManagerClients.updateSQL(id, overrideCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE,
194
					ImmutableMap.of("level", level, "apiId", apiId, "dsId", id));
195
		} else {
196
			datasourceManagerClients.updateSQL(id, resetCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE, ImmutableMap.of("apiId", apiId, "dsId", id));
197
		}
182 198
	}
183 199

  
184 200
	@Override
185 201
	public void setLastCollectionInfo(final String dsId, final String apiId, final String mdId, final Integer size, final Date date)
186 202
			throws DsmException {
187
		setLastOperationInfo(setLastCollectionInfo, dsId, apiId, mdId, size, date);
203
		setLastOperationInfo(setLastCollectionInfo, fixDsId(dsId), apiId, mdId, size, date);
188 204
	}
189 205

  
190 206
	@Override
191 207
	public void setLastAggregationInfo(final String dsId, final String apiId, final String mdId, final Integer size, final Date date)
192 208
			throws DsmException {
193
		setLastOperationInfo(setLastAggregationInfo, dsId, apiId, mdId, size, date);
209
		setLastOperationInfo(setLastAggregationInfo, fixDsId(dsId), apiId, mdId, size, date);
194 210
	}
195 211

  
196 212
	@Override
197 213
	public void setLastDownloadInfo(final String dsId, final String apiId, final String objId, final Integer size, final Date date)
198 214
			throws DsmException {
199
		setLastOperationInfo(setLastDownloadInfo, dsId, apiId, objId, size, date);
215
		setLastOperationInfo(setLastDownloadInfo, fixDsId(dsId), apiId, objId, size, date);
200 216
	}
201 217

  
202 218
	private void setLastOperationInfo(final Resource sqlResource, final String dsId, final String apiId, final String mdId, final Integer size, final Date date)
......
217 233
			final String baseUrl,
218 234
			final Map<String, String> params)
219 235
			throws DsmException {
236

  
237
		final String id = fixDsId(dsId);
238

  
220 239
		// Delete old params
221
		datasourceManagerClients.updateSQL(dsId, "DELETE FROM dsm_apiparams WHERE api = :api", AfterSqlUpdate.NONE, ImmutableMap.of("api", apiId));
240
		datasourceManagerClients.updateSQL(id, "DELETE FROM dsm_apiparams WHERE api = :api", AfterSqlUpdate.NONE, ImmutableMap.of("api", apiId));
222 241

  
223 242
		// Insert new params
224 243
		for (final Map.Entry<String, String> e : params.entrySet()) {
225 244
			final Map<String, Object> sqlParams = ImmutableMap.of("param", e.getKey(), "value", e.getValue(), "api", apiId);
226
			datasourceManagerClients.updateSQL(dsId, insertApiParam, AfterSqlUpdate.NONE, sqlParams);
245
			datasourceManagerClients.updateSQL(id, insertApiParam, AfterSqlUpdate.NONE, sqlParams);
227 246
		}
228 247

  
229 248
		// Update the BaseURL
230
		datasourceManagerClients.updateSQL(dsId,
249
		datasourceManagerClients.updateSQL(id,
231 250
				"UPDATE dsm_api SET baseurl = :baseurl WHERE id = :api",
232 251
				AfterSqlUpdate.NONE,
233 252
				ImmutableMap.of("baseurl", baseUrl, "api", apiId));
234 253

  
235 254
		// Update the metadata_identifier_path
236
		datasourceManagerClients.updateSQL(dsId,
255
		datasourceManagerClients.updateSQL(id,
237 256
				"UPDATE dsm_api SET metadata_identifier_path = :path WHERE id = :api",
238 257
				AfterSqlUpdate.NONE,
239 258
				ImmutableMap.of("path", metadataIdentifierPath, "api", apiId));
240 259

  
241 260
		// Update the IS profile
242
		datasourceManagerClients.regenerateProfile(dsId);
261
		datasourceManagerClients.regenerateProfile(id);
243 262
	}
244 263

  
245 264
	@Override
......
297 316
		return datasourceManagerClients;
298 317
	}
299 318

  
319
	private String fixDsId(final String dsId) throws DsmException {
320
		return dsId.endsWith(REPO_PROFILEID_SUFFIX) ? datasourceManagerClients.findDatasourceId(dsId) : dsId;
321
	}
322

  
300 323
	@Required
301 324
	public void setDatasourceManagerClients(final DatasourceManagerClients datasourceManagerClients) {
302 325
		this.datasourceManagerClients = datasourceManagerClients;

Also available in: Unified diff