1 |
1 |
package eu.dnetlib.repo.manager.server;
|
2 |
2 |
|
|
3 |
import com.unboundid.util.Base64;
|
3 |
4 |
import eu.dnetlib.domain.data.Repository;
|
|
5 |
import eu.dnetlib.domain.data.RepositoryInterface;
|
|
6 |
import eu.dnetlib.domain.enabling.Vocabulary;
|
4 |
7 |
import eu.dnetlib.repo.manager.client.RepositoryService;
|
5 |
8 |
import eu.dnetlib.repo.manager.server.utils.Constants;
|
6 |
9 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
|
... | ... | |
15 |
18 |
import org.springframework.beans.factory.annotation.Value;
|
16 |
19 |
import org.springframework.stereotype.Service;
|
17 |
20 |
|
|
21 |
import java.text.Normalizer;
|
18 |
22 |
import java.util.*;
|
19 |
23 |
|
20 |
24 |
/**
|
... | ... | |
167 |
171 |
}
|
168 |
172 |
|
169 |
173 |
@Override
|
|
174 |
public List<String> getDatasourceClasses(String mode) throws RepositoryServiceException {
|
|
175 |
try {
|
|
176 |
LOGGER.debug("Getting datasource classes for mode: " + mode);
|
|
177 |
List<String> retList = new ArrayList<String>();
|
|
178 |
|
|
179 |
for ( String datasourceClass : vocabularyLoader.getVocabulary("dnet:datasource_typologies", Locale.ENGLISH, Locale.ROOT).getEnglishNames()) {
|
|
180 |
if (mode.equalsIgnoreCase("aggregator")) {
|
|
181 |
if (datasourceClass.contains("Aggregator"))
|
|
182 |
retList.add(datasourceClass);
|
|
183 |
} else if (mode.equalsIgnoreCase("aggregator")) {
|
|
184 |
|
|
185 |
}
|
|
186 |
|
|
187 |
}
|
|
188 |
return retList;
|
|
189 |
|
|
190 |
} catch (Exception e) {
|
|
191 |
LOGGER.error("Error while getting datasource classes for mode: " + mode, e);
|
|
192 |
emailUtils.reportException(e);
|
|
193 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
@Override
|
170 |
198 |
public void storeRepository(Repository repo, String mode) throws RepositoryServiceException {
|
171 |
199 |
|
172 |
200 |
|
173 |
|
/* try {
|
174 |
|
LOGGER.debug("Getting repository with id: " + repoId + " and name: " + officialName);
|
|
201 |
try {
|
|
202 |
LOGGER.debug("Storing repository with name: " + repo.getOfficialName());
|
|
203 |
repo.setCountryCode(getCountryCode(repo.getCountryName()));
|
175 |
204 |
|
176 |
|
Repository repo = this.repoAPI.getRepository(officialName, repoId);
|
177 |
|
if (repo == null) {
|
178 |
|
throw new RepositoryServiceException("registration.repositoryNotExists", RepositoryServiceException.ErrorCode.REPOSITORY_NOT_EXISTS);
|
|
205 |
repo.setActivationId(UUID.randomUUID().toString());
|
|
206 |
// repo.setRegisteredBy((String) session.get(Constants.loggedInField));
|
|
207 |
|
|
208 |
if (mode.equals("opendoar") || mode.equals("re3data")) {
|
|
209 |
repo.setProvenanceActionClass("sysimport:crosswalk:entityregistry");
|
|
210 |
// repo.setId(this.id);
|
|
211 |
} else if (mode.equals("journal")) {
|
|
212 |
repo.setProvenanceActionClass("user:insert");
|
|
213 |
repo.setCollectedFrom("infrastruct_::openaire");
|
|
214 |
repo.setDatasourceClass("pubsrepository::journal");
|
|
215 |
if(repo.getIssn() != null && repo.getIssn().length() == 0)
|
|
216 |
repo.setIssn(Base64.encode(repo.getOfficialName()).substring(0,8));
|
|
217 |
repo.setId("openaire____::issn" + repo.getIssn());
|
|
218 |
repo.setNamespacePrefix("issn" + repo.getIssn());
|
|
219 |
} else if (mode.equals("aggregator")) {
|
|
220 |
repo.setProvenanceActionClass("user:insert");
|
|
221 |
repo.setCollectedFrom("infrastruct_::openaire");
|
|
222 |
repo.setDatasourceClass(getDatasourceClassCode(repo.getDatasourceClass()));
|
|
223 |
repo.setId("openaire____::" + Base64.encode(repo.getOfficialName()));
|
|
224 |
repo.setNamespacePrefix( Normalizer.normalize(repo.getOfficialName().toLowerCase().replace(" ", "_"), Normalizer.Form.NFD).replaceAll("[^a-zA-Z0-9]", ""));
|
|
225 |
if (repo.getNamespacePrefix().length() > 12) {
|
|
226 |
repo.setNamespacePrefix(repo.getNamespacePrefix().substring(0,12));
|
|
227 |
} else {
|
|
228 |
while (repo.getNamespacePrefix().length() < 12)
|
|
229 |
repo.setNamespacePrefix(repo.getNamespacePrefix().concat("_"));
|
|
230 |
}
|
179 |
231 |
}
|
180 |
|
return repo;
|
181 |
232 |
|
|
233 |
this.repoAPI.storeRepository(repo,mode, repo.getInterfaces());
|
|
234 |
|
182 |
235 |
} catch (Exception e) {
|
183 |
|
LOGGER.error("Error while getting repository with id: " + repoId + " and name: " + officialName);
|
|
236 |
LOGGER.error("Error while Storing repository with name: " + repo.getOfficialName(), e);
|
184 |
237 |
if (e instanceof RepositoryServiceException) {
|
185 |
238 |
throw (RepositoryServiceException) e;
|
186 |
239 |
} else {
|
187 |
240 |
emailUtils.reportException(e);
|
188 |
241 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
189 |
242 |
}
|
190 |
|
}*/
|
|
243 |
}
|
191 |
244 |
}
|
192 |
245 |
|
|
246 |
@Override
|
|
247 |
public void updateRepositoryInformation(Repository repo) throws RepositoryServiceException {
|
|
248 |
try {
|
|
249 |
LOGGER.debug("Updating information of repo: " + repo.getOfficialName());
|
|
250 |
repo.setDatasourceClass(getDatasourceClassCode(repo.getDatasourceClass()));
|
|
251 |
this.repoAPI.updateRepositoryInformation(repo);
|
193 |
252 |
|
|
253 |
} catch (Exception e) {
|
|
254 |
LOGGER.error("Error while updating information of repo: " + repo.getOfficialName(), e);
|
|
255 |
if (e instanceof RepositoryServiceException) {
|
|
256 |
throw (RepositoryServiceException) e;
|
|
257 |
} else {
|
|
258 |
emailUtils.reportException(e);
|
|
259 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
|
260 |
}
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
194 |
264 |
private Tuple<List<Repository>, List<Repository>> getRepositoriesByCountryTesting(String country, String mode, boolean includeUnknownCountries) throws RepositoryServiceException {
|
195 |
265 |
try {
|
196 |
266 |
LOGGER.debug("Getting testing repositories of country: " + country + " with type: " + mode + " and includeUnknownCountries: " + includeUnknownCountries);
|
... | ... | |
226 |
296 |
}
|
227 |
297 |
}
|
228 |
298 |
|
|
299 |
private String getCountryCode(String countryName) {
|
|
300 |
Vocabulary countries = vocabularyLoader.getVocabulary("dnet:countries", Locale.ENGLISH, Locale.ROOT);
|
|
301 |
|
|
302 |
return countries.getEncoding(countryName);
|
|
303 |
}
|
|
304 |
|
|
305 |
private String getDatasourceClassCode(String datasourceClassName) {
|
|
306 |
Vocabulary datasourceClasses = vocabularyLoader.getVocabulary("dnet:datasource_typologies", Locale.ENGLISH, Locale.ROOT);
|
|
307 |
|
|
308 |
return datasourceClasses.getEncoding(datasourceClassName);
|
|
309 |
}
|
|
310 |
|
229 |
311 |
/* @Override
|
230 |
312 |
public List<Repository> getRepositoriesByCountry(String country, String mode) throws RepositoryServiceException {
|
231 |
313 |
try {
|
added methods to get the available datasourceClasses, register a datasource and updates it's basic information