Project

General

Profile

« Previous | Next » 

Revision 34575

verification of already registered services

View differences:

DatabaseUtils.java
1 1
package eu.dnetlib.enabling.is.jdbc;
2 2

  
3 3
import java.io.IOException;
4
import java.util.Collection;
4 5
import java.util.List;
5 6
import java.util.Map;
6 7

  
......
13 14
import org.springframework.beans.factory.annotation.Required;
14 15
import org.springframework.jdbc.core.JdbcTemplate;
15 16

  
17
import com.google.common.collect.Lists;
18

  
16 19
import eu.dnetlib.enabling.is.rmi.InformationServiceException;
17 20
import eu.dnetlib.enabling.is.rmi.Operation;
18 21

  
......
37 40
		return jdbcTemplate.update(sql);
38 41
	}
39 42

  
43
	public boolean isRegisteredService(final String address) {
44
		final String sql = "SELECT service from service_protocols where address = ?";
45
		final List<String> list = jdbcTemplate.queryForList(sql, String.class, address);
46
		return list != null && !list.isEmpty();
47
	}
48

  
40 49
	public boolean isRegisteredDs(final String code, final String type) {
41 50
		final String sql = "SELECT id from datastructures where code = ? and type = ?";
42 51
		final List<String> list = jdbcTemplate.queryForList(sql, String.class, code, type);
43 52
		return list != null && !list.isEmpty();
44 53
	}
45 54

  
46
	public String findDsIdByCode(final String code, final String type) throws InformationServiceException {
47
		final String sql = "SELECT id from datastructures where code = ? and type = ?";
55
	public String findServiceIdByAddress(final String... addrs) {
56
		return findServiceIdByAddress(Lists.newArrayList(addrs));
57
	}
48 58

  
49
		final List<String> list = jdbcTemplate.queryForList(sql, String.class, code, type);
50
		if (list == null || list.isEmpty()) {
51
			throw new InformationServiceException(String.format("Missing datastructure with code %s and type %s", code, type));
52
		} else if (list.size() > 1) {
53
			throw new InformationServiceException(String.format("Too many datastructure with code %s and type %s", code, type));
54
		} else {
55
			return list.get(0);
59
	public String findServiceIdByAddress(final Collection<String> addresses) {
60
		final String sql = "SELECT service from service_protocols where address = ?";
61
		for (String addr : addresses) {
62
			final List<String> list = jdbcTemplate.queryForList(sql, String.class, addr);
63
			if (list != null && !list.isEmpty()) { return list.get(0); }
56 64
		}
65
		return null;
57 66
	}
58 67

  
68
	public String findDsIdByCode(final String code, final String type) {
69
		final String sql = "SELECT id from datastructures where code = ? and type = ?";
70
		final List<String> list = jdbcTemplate.queryForList(sql, String.class, code, type);
71
		return list == null || list.isEmpty() ? null : list.get(0);
72
	}
73

  
59 74
	public void registerNotificationTrigger(final Operation operation, final String table) throws InformationServiceException {
60 75
		try {
61 76
			final StringTemplate st = new StringTemplate();

Also available in: Unified diff