Project

General

Profile

« Previous | Next » 

Revision 54970

View differences:

SimpleDatasourceManagerCore.java
309 309
	public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level, final boolean override)
310 310
			throws DatasourceManagerServiceException {
311 311
		try {
312
			final String profId = fixDsId(dsId);
313

  
312 314
			if (override) {
315
				final String profile = obtainProfile(profId);
316
				final SAXReader reader = new SAXReader();
317
				final Document doc = reader.read(new StringReader(profile));
313 318

  
314
				final String xq =
315
						String.format("for $x in doc('/db/DRIVER/%s')//INTERFACE[@id = '%s']/@compliance return update replace $x with '%s'",
316
								fixDsId(dsId), ifaceId, level);
317
				return is.xupdate(xq);
318
			} else {
319
				final Element iface = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
320
				if (iface != null) {
321
					final Map<String, String> fields = new HashMap<>();
319 322

  
320
				final String profId = fixDsId(dsId);
323
					if (!StringUtils.isEmpty(level)) {
324
						fields.put(OVERRIDING_COMPLIANCE_FIELD, level);
325
					}
321 326

  
322
				try {
323
					final String profile = obtainProfile(profId);
327
					while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
328
						final Node node = iface.selectSingleNode("./INTERFACE_EXTRA_FIELD");
329
						final String name = node.valueOf("@name");
324 330

  
325
					final SAXReader reader = new SAXReader();
326
					final Document doc = reader.read(new StringReader(profile));
327

  
328
					final Element iface = (Element) doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
329
					if (iface != null) {
330
						final Map<String, String> fields = new HashMap<>();
331

  
332
						if (!StringUtils.isEmpty(level)) {
333
							fields.put(OVERRIDING_COMPLIANCE_FIELD, level);
331
						if (!name.equals(OVERRIDING_COMPLIANCE_FIELD)) {
332
							fields.put(node.valueOf("@name"), node.getText());
334 333
						}
334
						node.detach();
335
					}
335 336

  
336
						while (iface.selectNodes("./INTERFACE_EXTRA_FIELD").size() > 0) {
337
							final Node node = iface.selectSingleNode("./INTERFACE_EXTRA_FIELD");
338
							final String name = node.valueOf("@name");
339

  
340
							if (!name.equals(OVERRIDING_COMPLIANCE_FIELD)) {
341
								fields.put(node.valueOf("@name"), node.getText());
342
							}
343
							node.detach();
337
					for (final Map.Entry<String, String> e : fields.entrySet()) {
338
						if ((e.getValue() != null) && !e.getValue().isEmpty()) {
339
							final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
340
							field.addAttribute("name", e.getKey());
341
							field.addText(e.getValue());
344 342
						}
345

  
346
						for (final Map.Entry<String, String> e : fields.entrySet()) {
347
							if ((e.getValue() != null) && !e.getValue().isEmpty()) {
348
								final Element field = iface.addElement("INTERFACE_EXTRA_FIELD");
349
								field.addAttribute("name", e.getKey());
350
								field.addText(e.getValue());
351
							}
352
						}
353
						is.updateProfile(profId, doc.asXML());
354
					} else {
355
						log.error("Invalid interface: " + ifaceId);
356
						throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
357 343
					}
358
				} catch (final Exception e) {
359
					log.error("Error updating API of profile: " + profId);
360
					throw new DatasourceManagerServiceException("Error updating API of profile: " + profId, e);
344
					is.updateProfile(profId, doc.asXML());
345
				} else {
346
					log.error("Invalid interface: " + ifaceId);
347
					throw new DatasourceManagerServiceException("Missing interface: " + ifaceId);
361 348
				}
362

  
363 349
				return true;
350
			} else {
351
				final String xq =
352
						String.format("for $x in doc('/db/DRIVER/%s')//INTERFACE[@id = '%s']/@compliance return update replace $x with '%s'",
353
								profId, ifaceId, level);
354
				return is.xupdate(xq);
364 355
			}
365 356
		} catch (final Exception e) {
366 357
			log.error("Error updating profile: " + dsId, e);
......
369 360
	}
370 361

  
371 362
	@Override
363
	public boolean resetLevelOfCompliance(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
364
		return deleteExtraField(dsId, ifaceId, OVERRIDING_COMPLIANCE_FIELD);
365
	}
366

  
367
	@Override
372 368
	public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
373 369
		try {
374 370
			final String xq =
......
480 476
		try {
481 477

  
482 478
			final String profile = obtainProfile(profId);
479

  
480
			System.out.println(profile);
481

  
483 482
			final Document doc = new SAXReader().read(new StringReader(profile));
484 483

  
485 484
			final Node ef = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']/INTERFACE_EXTRA_FIELD[@name = '" + field + "']");

Also available in: Unified diff