Project

General

Profile

« Previous | Next » 

Revision 47676

fine grained operations

View differences:

DatasourcesApiController.java
4 4

  
5 5
import eu.dnetlib.common.rmi.DNetRestDocumentation;
6 6
import eu.dnetlib.datasource.publisher.clients.ClientResponse;
7
import eu.dnetlib.datasource.publisher.clients.DatasourceInfoRetriever;
7
import eu.dnetlib.datasource.publisher.clients.DatasourceDao;
8 8
import eu.dnetlib.datasource.publisher.model.BrowseTerm;
9 9
import eu.dnetlib.datasource.publisher.model.DatasourceResponse;
10
import eu.dnetlib.datasource.publisher.model.db.Api;
11
import eu.dnetlib.datasource.publisher.model.db.Datasource;
10 12
import eu.dnetlib.datasource.publisher.model.db.SearchInterfacesEntry;
13

  
14
import org.apache.commons.lang.StringUtils;
11 15
import org.apache.commons.logging.Log;
12 16
import org.apache.commons.logging.LogFactory;
13 17
import org.apache.http.HttpStatus;
......
22 26
	private static final Log log = LogFactory.getLog(DatasourcesApiController.class);
23 27

  
24 28
	@Autowired
25
	private DatasourceInfoRetriever dsInfoRetriever;
29
	private DatasourceDao dsDao;
26 30

  
27 31
	@Override
28 32
	@RequestMapping(value = "/ds/list/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
29 33
    public List<String> listIds(@PathVariable int page, @PathVariable int size) throws ApiException {
30
	    return dsInfoRetriever.listIds(new PageRequest(page, size));
34
	    return dsDao.listIds(new PageRequest(page, size));
31 35
    }
32 36

  
33 37
    @Override
......
38 42
		    log.debug(String.format("getDatasourceInfo(dsId = %s)", id));
39 43
	    }
40 44

  
41
	    final ClientResponse clientResponse = dsInfoRetriever.getInfo(id);
45
	    final ClientResponse clientResponse = dsDao.getInfo(id);
42 46
    	return clientResponse.getDatasourceResponse();
43 47
    }
44 48

  
......
46 50
	@RequestMapping(value = "/ds/search/name/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
47 51
	public List<DatasourceResponse> searchByName(
48 52
			@RequestParam final String name, @PathVariable final int page, @PathVariable final int size) {
49
		return dsInfoRetriever.searchByName(name, new PageRequest(page, size));
53
		return dsDao.searchByName(name, new PageRequest(page, size));
50 54
	}
51 55

  
52 56
	@Override
53 57
	@RequestMapping(value = "/ds/search/email/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
54 58
	public List<DatasourceResponse> searchByContactemail(
55 59
			@RequestParam final String contactemail, @PathVariable final int page, @PathVariable final int size) {
56
		return dsInfoRetriever.searchByContactemail(contactemail, new PageRequest(page, size));
60
		return dsDao.searchByContactemail(contactemail, new PageRequest(page, size));
57 61
	}
58 62

  
59 63
	@Override
60 64
	@RequestMapping(value = "/ds/search/country/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
61 65
	public List<DatasourceResponse> searchByCountry(
62 66
			@RequestParam final String country, @PathVariable final int page, @PathVariable final int size) {
63
		return dsInfoRetriever.searchByCountry(country, new PageRequest(page, size));
67
		return dsDao.searchByCountry(country, new PageRequest(page, size));
64 68
	}
65 69

  
66 70
	@Override
67 71
	@RequestMapping(value = "/api/search/{field}", produces = { "application/json" }, method = RequestMethod.GET)
68 72
	public List<SearchInterfacesEntry> searchInterface(@PathVariable final String field, @RequestParam final String value) {
69
		return dsInfoRetriever.searchInterface(field, value);
73
		return dsDao.searchInterface(field, value);
70 74
	}
71 75

  
72 76
	@Override
......
74 78
	public List<? extends BrowseTerm> browseField(@PathVariable final String field) throws ApiException {
75 79
		switch (field) {
76 80
		case "country":
77
			return dsInfoRetriever.browseCountries();
81
			return dsDao.browseCountries();
78 82
		case "typology":
79
			return dsInfoRetriever.browseTypologies();
83
			return dsDao.browseTypologies();
80 84
		case "protocol":
81
			return dsInfoRetriever.browseProtocols();
85
			return dsDao.browseProtocols();
82 86
		case "compatibility":
83
			return dsInfoRetriever.browseCompatibility();
87
			return dsDao.browseCompatibility();
84 88
		case "activation":
85
			return dsInfoRetriever.browseActivation();
89
			return dsDao.browseActivation();
86 90
		default:
87 91
			throw new ApiException(HttpStatus.SC_BAD_REQUEST, String.format("unsupported browse field '%s'", field));
88 92
		}
89 93
	}
90 94

  
91 95
	@Override
96
	@RequestMapping(value = "/ds/api/{dsId}", produces = { "application/json" }, method = RequestMethod.GET)
97
	public List<Api> getApi(@PathVariable final String dsId) throws ApiException {
98
		return dsDao.getApi(dsId);
99
	}
100

  
101
	@Override
102
	@RequestMapping(value = "/ds/api/{dsId}", method = RequestMethod.DELETE)
103
	public void deleteApi(@PathVariable final String apiId) throws ApiException {
104
		dsDao.deleteApi(apiId);
105
	}
106

  
107
	@Override
108
	@RequestMapping(value = "/ds/api/add", method = RequestMethod.POST)
109
	public void addApi(@RequestParam final Api api) throws ApiException {
110
		if (StringUtils.isBlank(api.getDatasource())) {
111
			throw new ApiException(HttpStatus.SC_BAD_REQUEST, "missing datasource id");
112
		}
113
		dsDao.addApi(api);
114
	}
115

  
116
	@Override
92 117
	@RequestMapping(value = "/ds/manage", method = RequestMethod.POST)
93 118
	public void setManaged(@RequestParam final String id, @RequestParam final boolean managed) {
94
		dsInfoRetriever.setManaged(id, managed);
119
		dsDao.setManaged(id, managed);
95 120
	}
96 121

  
122
	@Override
123
	@RequestMapping(value = "/ds/add", method = RequestMethod.POST)
124
	public void saveDatasource(@RequestBody final Datasource datasource) throws ApiException {
125
		if (dsDao.exist(datasource)) { //TODO further check that the DS doesn't have any API
126
			throw new ApiException(HttpStatus.SC_CONFLICT, String.format("cannot already defined '%s'", datasource.getId()));
127
		}
128
		dsDao.save(datasource);
129
	}
130

  
131
	@Override
132
	@RequestMapping(value = "/ds/update/officialname", method = RequestMethod.POST)
133
	public void updateOfficialname(@RequestParam final String dsId, @RequestParam final String officialname) throws ApiException {
134
		dsDao.updateOfficialName(dsId, officialname);
135
	}
136

  
137
	@Override
138
	@RequestMapping(value = "/ds/update/englishname", method = RequestMethod.POST)
139
	public void updateEnglishname(@RequestParam final String dsId, @RequestParam final String englishname) throws ApiException {
140
		dsDao.updateEnglishName(dsId, englishname);
141
	}
142

  
143
	@Override
144
	@RequestMapping(value = "/ds/update/latitude", method = RequestMethod.POST)
145
	public void updateLatitude(final String dsId, final Double latitude) throws ApiException {
146
		dsDao.updateLatitude(dsId, latitude);
147
	}
148

  
149
	@Override
150
	@RequestMapping(value = "/ds/update/longitude", method = RequestMethod.POST)
151
	public void updateLongitude(final String dsId, final Double longitude) throws ApiException {
152
		dsDao.updateLongitude(dsId, longitude);
153
	}
154

  
97 155
}

Also available in: Unified diff