changed to make the API return 404 if the resource is not available

This commit is contained in:
Miriam Baglioni 2023-05-10 17:44:19 +02:00
parent f025c47214
commit 17c1ad7de1
11 changed files with 137 additions and 118 deletions

View File

@ -136,7 +136,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.8</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -329,11 +329,17 @@ public class ISClientImpl implements ISClient {
final List<String> res = Lists.newArrayList();
log.debug(String.format("running xquery:\n%s", xquery));
final List<String> list = isLookUpService.quickSearchProfile(xquery);
if (list != null) {
res.addAll(list);
try{
final List<String> list = isLookUpService.quickSearchProfile(xquery);
if (list != null) {
res.addAll(list);
}
log.debug(String.format("query result size: %s", res.size()));
}catch(Exception ex){
log.error(ex.getMessage());
throw new ISLookUpException("");
}
log.debug(String.format("query result size: %s", res.size()));
return res;
}

View File

@ -11,7 +11,7 @@ import static eu.dnetlib.openaire.common.ExporterConstants.W;
import java.util.List;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.CommunityNotFoundException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
@ -72,7 +72,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getCommunity(id);
}
@ -89,7 +89,7 @@ public class CommunityApiController {
})
public void setCommunity(
@PathVariable final String id,
@RequestBody final CommunityWritableProperties properties) throws CommunityException, CommunityNotFoundException {
@RequestBody final CommunityWritableProperties properties) throws CommunityException, ResourceNotFoundException {
communityApiCore.setCommunity(id, properties);
}
@ -105,7 +105,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityProject> getCommunityProjects(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityProject> getCommunityProjects(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getCommunityProjects(id);
}
@ -122,7 +122,7 @@ public class CommunityApiController {
})
public CommunityProject addCommunityProject(
@PathVariable final String id,
@RequestBody final CommunityProject project) throws CommunityException, CommunityNotFoundException {
@RequestBody final CommunityProject project) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityProject(id, project);
}
@ -140,7 +140,7 @@ public class CommunityApiController {
})
public void deleteCommunityProject(
@PathVariable final String id,
@RequestBody final Integer projectId) throws CommunityException, CommunityNotFoundException {
@RequestBody final Integer projectId) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityProject(id, projectId);
}
@ -159,7 +159,7 @@ public class CommunityApiController {
})
public List<CommunityProject> addCommunityProjectList(
@PathVariable final String id,
@RequestBody final List<CommunityProject> projectList) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<CommunityProject> projectList) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityProjectList(id, projectList);
}
@ -178,7 +178,7 @@ public class CommunityApiController {
})
public void deleteCommunityProjectList(
@PathVariable final String id,
@RequestBody final List<Integer> projectIdList) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityProjectList(id, projectIdList);
}
@ -194,7 +194,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityContentprovider> getCommunityContentproviders(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getCommunityContentproviders(id);
}
@ -211,7 +211,7 @@ public class CommunityApiController {
})
public CommunityContentprovider addCommunityContentprovider(
@PathVariable final String id,
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException, CommunityNotFoundException {
@RequestBody final CommunityContentprovider contentprovider) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityContentprovider(id, contentprovider);
}
@ -229,7 +229,7 @@ public class CommunityApiController {
})
public void removeCommunityContentprovider(
@PathVariable final String id,
@RequestBody final Integer contentproviderId) throws CommunityException, CommunityNotFoundException {
@RequestBody final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityContentProvider(id, contentproviderId);
}
@ -248,7 +248,7 @@ public class CommunityApiController {
})
public List<CommunityContentprovider> addCommunityContentProvidersList(
@PathVariable final String id,
@RequestBody final List<CommunityContentprovider> contentprovidersList) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<CommunityContentprovider> contentprovidersList) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityContentProvidersList(id, contentprovidersList);
}
@ -267,7 +267,7 @@ public class CommunityApiController {
})
public void deleteCommunityContentProvidersList(
@PathVariable final String id,
@RequestBody final List<Integer> contentProviderIdList) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<Integer> contentProviderIdList) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityContentProviderList(id, contentProviderIdList);
}
@ -285,7 +285,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityOrganization> getCommunityOrganizations(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getCommunityOrganizations(id);
}
@ -302,7 +302,7 @@ public class CommunityApiController {
})
public CommunityOrganization addCommunityOrganization(
@PathVariable final String id,
@RequestBody final CommunityOrganization organization) throws CommunityException, CommunityNotFoundException {
@RequestBody final CommunityOrganization organization) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityOrganization(id, organization);
}
@ -320,7 +320,7 @@ public class CommunityApiController {
})
public void removeCommunityOrganization(
@PathVariable final String id,
@RequestBody final Integer organizationId) throws CommunityException, CommunityNotFoundException {
@RequestBody final Integer organizationId) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityOrganization(id, organizationId);
}
@ -339,7 +339,7 @@ public class CommunityApiController {
})
public CommunityDetails addCommunitySubjects(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunitySubjects(id, subjects);
}
@ -357,7 +357,7 @@ public class CommunityApiController {
})
public CommunityDetails removeCommunitySubjects(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.removeCommunitySubjects(id, subjects);
}
@ -372,7 +372,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails addCommunityFOS(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityFOS(id, subjects);
}
@ -388,7 +388,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails removeCommunityFOS(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.removeCommunityFOS(id, subjects);
}
@ -405,7 +405,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails addCommunitySDG(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunitySDG(id, subjects);
}
@ -421,7 +421,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails removeCommunitySDG(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return communityApiCore.removeCommunitySDG(id, subjects);
}
@ -437,7 +437,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails addAdvancedConstraint(
@PathVariable final String id,
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException, CommunityNotFoundException {
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityAdvancedConstraint(id, advancedConstraint);
}
@ -452,7 +452,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error") })
public CommunityDetails removeAdvancedConstraint(
@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.removeCommunityAdvancedConstraint(id);
}
@ -468,7 +468,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getCommunityZenodoCommunities(id);
}
@ -485,7 +485,7 @@ public class CommunityApiController {
})
public CommunityZenodoCommunity addCommunityZenodoCommunity(
@PathVariable final String id,
@RequestBody final CommunityZenodoCommunity zenodocommunity) throws CommunityException, CommunityNotFoundException {
@RequestBody final CommunityZenodoCommunity zenodocommunity) throws CommunityException, ResourceNotFoundException {
return communityApiCore.addCommunityZenodoCommunity(id, zenodocommunity);
@ -504,7 +504,7 @@ public class CommunityApiController {
})
public void removeCommunityZenodoCommunity(
@PathVariable final String id,
@RequestBody final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException {
@RequestBody final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
communityApiCore.removeCommunityZenodoCommunity(id, zenodoCommId);
@ -522,7 +522,7 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOpenAIRECommunities getOpenAireCommunities(
@PathVariable final String zenodoId) throws CommunityException, CommunityNotFoundException {
@PathVariable final String zenodoId) throws CommunityException, ResourceNotFoundException {
return communityApiCore.getOpenAIRECommunities(zenodoId);

View File

@ -6,7 +6,7 @@ import java.util.stream.Collectors;
import com.google.gson.Gson;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.CommunityNotFoundException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
@ -54,19 +54,19 @@ public class CommunityApiCore {// implements CommunityClient{
}
public CommunityDetails getCommunity(final String id) throws CommunityException, CommunityNotFoundException {
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
return cc.getCommunity(id);
}
private void removeAdvancedConstraint(String id) throws CommunityNotFoundException, CommunityException {
private void removeAdvancedConstraint(String id) throws ResourceNotFoundException, CommunityException {
cc.getCommunity(id);
isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "", false);
cc.removeAdvancedConstraint(id);
}
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, CommunityNotFoundException {
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
cc.getCommunity(id); // ensure the community exists.
@ -113,12 +113,12 @@ public class CommunityApiCore {// implements CommunityClient{
cc.updateCommunity(id, details);
}
public List<CommunityProject> getCommunityProjects(final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityProject> getCommunityProjects(final String id) throws CommunityException, ResourceNotFoundException {
cc.getCommunity(id); // ensure the community exists.
return cc.getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c));
}
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, CommunityNotFoundException {
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
if (!StringUtils.equalsIgnoreCase(id, project.getCommunityId())) {
throw new CommunityException("parameters 'id' and project.communityId must be coherent");
}
@ -127,7 +127,7 @@ public class CommunityApiCore {// implements CommunityClient{
}
private CommunityProject updateProject(String id, CommunityProject project) throws CommunityException, CommunityNotFoundException {
private CommunityProject updateProject(String id, CommunityProject project) throws CommunityException, ResourceNotFoundException {
final TreeMap<Integer, CommunityProject> projects = getCommunityProjectMap(id);
String project_id = project.getId();
@ -162,7 +162,7 @@ public class CommunityApiCore {// implements CommunityClient{
return project;
}
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList) throws CommunityException, CommunityNotFoundException {
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList) throws CommunityException, ResourceNotFoundException {
if(projectList == null || projectList.size() == 0){
throw new CommunityException("parameter 'projectList' must be present and should contain at least one project");
}
@ -184,35 +184,35 @@ public class CommunityApiCore {// implements CommunityClient{
return String.valueOf(id + 1);
}
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, CommunityNotFoundException {
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityProject> projects = getCommunityProjectMap(id);
if (!projects.containsKey(projectId)) {
throw new CommunityNotFoundException(String.format("project '%s' doesn't exist within context '%s'", projectId, id));
throw new ResourceNotFoundException(String.format("project '%s' doesn't exist within context '%s'", projectId, id));
}
isClient.removeConcept(id, id + PROJECTS_ID_SUFFIX, id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + projectId);
cc.removeFromCategory(id, PROJECTS_ID_SUFFIX, String.valueOf(projectId));
}
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, CommunityNotFoundException {
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
for(Integer projectId: projectIdList){
removeCommunityProject(id, projectId);
}
}
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
cc.getCommunity(id); // ensure the community exists.
return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
}
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
throws CommunityException, CommunityNotFoundException {
throws CommunityException, ResourceNotFoundException {
log.info("content provider to add " + cp.toString());
if (!StringUtils.equalsIgnoreCase(id, cp.getCommunityId())) { throw new CommunityException("parameters 'id' and cp.communityId must be coherent"); }
return updateContentprovider(id, cp);
}
private CommunityContentprovider updateContentprovider(String id, CommunityContentprovider cp) throws CommunityException, CommunityNotFoundException {
private CommunityContentprovider updateContentprovider(String id, CommunityContentprovider cp) throws CommunityException, ResourceNotFoundException {
final TreeMap<Integer, CommunityContentprovider> cps = getCommunityContentproviderMap(id);
final String concept_id = cp.getId();
if (concept_id != null && cps.keySet().contains(Integer.valueOf(concept_id))) {
@ -239,16 +239,16 @@ public class CommunityApiCore {// implements CommunityClient{
return cp;
}
public void removeCommunityContentProvider(final String id, final Integer contentproviderId) throws CommunityException, CommunityNotFoundException {
public void removeCommunityContentProvider(final String id, final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityContentprovider> providers = getCommunityContentproviderMap(id);
if (!providers.containsKey(contentproviderId)) {
throw new CommunityNotFoundException(String.format("content provider '%s' doesn't exist within context '%s'", contentproviderId, id));
throw new ResourceNotFoundException(String.format("content provider '%s' doesn't exist within context '%s'", contentproviderId, id));
}
isClient.removeConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId);
cc.removeFromCategory(id, CONTENTPROVIDERS_ID_SUFFIX, String.valueOf(contentproviderId));
}
public List<CommunityContentprovider> addCommunityContentProvidersList(String id, List<CommunityContentprovider> contentprovidersList) throws CommunityException, CommunityNotFoundException {
public List<CommunityContentprovider> addCommunityContentProvidersList(String id, List<CommunityContentprovider> contentprovidersList) throws CommunityException, ResourceNotFoundException {
if(contentprovidersList == null || contentprovidersList.size() == 0){
throw new CommunityException("parameter 'contentprovidersList' must be present and should contain at least one content provider");
}
@ -266,32 +266,32 @@ public class CommunityApiCore {// implements CommunityClient{
return contentproviders;
}
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList) throws CommunityException, CommunityNotFoundException {
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList) throws CommunityException, ResourceNotFoundException {
for(Integer contentProviderId: contentProviderIdList){
removeCommunityContentProvider(id, contentProviderId);
}
}
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, CommunityNotFoundException {
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityOrganization> organizations = getCommunityOrganizationMap(id);
if (!organizations.containsKey(organizationId)) {
throw new CommunityNotFoundException(String.format("organization '%s' doesn't exist within context '%s'", organizationId, id));
throw new ResourceNotFoundException(String.format("organization '%s' doesn't exist within context '%s'", organizationId, id));
}
isClient.removeConcept(id, id + ORGANIZATION_ID_SUFFIX, id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organizationId);
cc.removeFromCategory(id, ORGANIZATION_ID_SUFFIX, String.valueOf(organizationId));
}
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
return cc.getCommunityZenodoCommunities(id);
}
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
cc.getCommunity(id);
return cc.getCommunityInfo(id, ORGANIZATION_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityOrganization(id, c));
}
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, CommunityNotFoundException {
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -306,7 +306,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails removeCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, CommunityNotFoundException {
public CommunityDetails removeCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -321,7 +321,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, CommunityNotFoundException {
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -339,7 +339,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, CommunityNotFoundException {
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -354,7 +354,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, CommunityNotFoundException {
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
final Set<String> current = Sets.newHashSet();
@ -371,7 +371,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, CommunityNotFoundException {
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -386,7 +386,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) throws CommunityException, CommunityNotFoundException {
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) throws CommunityException, ResourceNotFoundException {
final CommunityDetails cd = new CommunityDetails();
@ -397,7 +397,7 @@ public class CommunityApiCore {// implements CommunityClient{
return cd;
}
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityNotFoundException, CommunityException {
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
removeAdvancedConstraint(id);
@ -407,11 +407,11 @@ public class CommunityApiCore {// implements CommunityClient{
@CacheEvict(value = "community-cache", allEntries = true)
public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException {
public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityZenodoCommunity> zcomms = getZenodoCommunityMap(id);
if (!zcomms.containsKey(zenodoCommId)) {
throw new CommunityNotFoundException(String.format("Zenodo community '%s' doesn't exist within context '%s'", zenodoCommId, id));
throw new ResourceNotFoundException(String.format("Zenodo community '%s' doesn't exist within context '%s'", zenodoCommId, id));
}
isClient.removeConcept(id, id + ZENODOCOMMUNITY_ID_SUFFIX, id + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zenodoCommId);
@ -421,7 +421,7 @@ public class CommunityApiCore {// implements CommunityClient{
@CacheEvict(value = "community-cache", allEntries = true)
public CommunityZenodoCommunity addCommunityZenodoCommunity(final String id, final CommunityZenodoCommunity zc)
throws CommunityException, CommunityNotFoundException {
throws CommunityException, ResourceNotFoundException {
if (!StringUtils.equalsIgnoreCase(id, zc.getCommunityId())) { throw new CommunityException("parameters 'id' and zc.communityId must be coherent"); }
if (!StringUtils.isNotBlank(zc.getZenodoid())) { throw new CommunityException("parameter zenodoid cannot be null or empty"); }
final TreeMap<Integer, CommunityZenodoCommunity> zcs = getZenodoCommunityMap(id);
@ -438,7 +438,7 @@ public class CommunityApiCore {// implements CommunityClient{
return zc;
}
public CommunityOpenAIRECommunities getOpenAIRECommunities(final String zenodoId) throws CommunityException, CommunityNotFoundException {
public CommunityOpenAIRECommunities getOpenAIRECommunities(final String zenodoId) throws CommunityException, ResourceNotFoundException {
if (cci.getInverseZenodoCommunityMap().containsKey(zenodoId)) {
return new CommunityOpenAIRECommunities().setZenodoid(zenodoId)
@ -450,7 +450,7 @@ public class CommunityApiCore {// implements CommunityClient{
// HELPERS
private TreeMap<Integer, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, CommunityNotFoundException {
private TreeMap<Integer, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityProjects(id).stream()
.collect(Collectors.toMap(p -> Integer.valueOf(p.getId()), Functions.identity(), (p1, p2) -> {
log.warn(String.format("duplicate project found: '%s'", p1.getId()));
@ -458,7 +458,7 @@ public class CommunityApiCore {// implements CommunityClient{
}, TreeMap::new));
}
private TreeMap<Integer, CommunityContentprovider> getCommunityContentproviderMap(final String id) throws CommunityException, CommunityNotFoundException {
private TreeMap<Integer, CommunityContentprovider> getCommunityContentproviderMap(final String id) throws CommunityException, ResourceNotFoundException {
log.info("getting community content provider map");
return getCommunityContentproviders(id).stream()
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
@ -467,7 +467,7 @@ public class CommunityApiCore {// implements CommunityClient{
}, TreeMap::new));
}
private TreeMap<Integer, CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, CommunityNotFoundException {
private TreeMap<Integer, CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityZenodoCommunities(id).stream()
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
log.warn(String.format("duplicate Zenodo community found: '%s'", cp1.getId()));
@ -475,7 +475,7 @@ public class CommunityApiCore {// implements CommunityClient{
}, TreeMap::new));
}
private TreeMap<Integer, CommunityOrganization> getCommunityOrganizationMap(final String id) throws CommunityException, CommunityNotFoundException {
private TreeMap<Integer, CommunityOrganization> getCommunityOrganizationMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityOrganizations(id).stream()
.collect(Collectors.toMap(o -> Integer.valueOf(o.getId()), Functions.identity(), (o1, o2) -> {
log.warn(String.format("duplicate content provider found: '%s'", o1.getId()));
@ -484,7 +484,7 @@ public class CommunityApiCore {// implements CommunityClient{
}
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
throws CommunityException, CommunityNotFoundException {
throws CommunityException, ResourceNotFoundException {
if (!StringUtils.equalsIgnoreCase(id, organization.getCommunityId())) {
throw new CommunityException("parameters 'id' and organization.communityId must be coherent");
}

View File

@ -4,11 +4,11 @@ import java.util.Map;
import java.util.Set;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.CommunityNotFoundException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
public interface CommunityClient {
Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, CommunityNotFoundException;
Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException;
void dropCache();

View File

@ -9,7 +9,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.CommunityNotFoundException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
@ -25,7 +25,7 @@ public class CommunityClientImpl implements CommunityClient {
@Override
@Cacheable("community-cache")
public Map<String, Set<String>> getInverseZenodoCommunityMap () throws CommunityException, CommunityNotFoundException {
public Map<String, Set<String>> getInverseZenodoCommunityMap () throws CommunityException, ResourceNotFoundException {
log.info("Creating the data structure. Not using cache");
final Map<String, Set<String>> inverseListMap = new HashMap<>();

View File

@ -5,7 +5,7 @@ import com.google.common.collect.Lists;
import com.google.gson.Gson;
import eu.dnetlib.openaire.common.ISClient;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.CommunityNotFoundException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import static eu.dnetlib.openaire.community.CommunityConstants.*;
@Component
public class CommunityCommon {
@ -65,15 +66,16 @@ public class CommunityCommon {
return Lists.newArrayList();
}
public CommunityDetails getCommunity(final String id) throws CommunityException, CommunityNotFoundException {
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
final Context context = getContextMap().get(id);
if (context == null || CommunityConstants.communityBlackList.contains(id)) {
throw new CommunityNotFoundException(String.format("community '%s' does not exist", id));
//ResponseStatusException(NOT_FOUND, "Unable to find resource");
throw new ResourceNotFoundException();
}
return CommunityMappingUtils.asCommunityProfile(context);
}
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, CommunityNotFoundException {
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
getCommunity(id); // ensure the community exists.
return getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c));
}

View File

@ -1,7 +1,12 @@
services.is.host = localhost
services.is.port = 8280
services.is.protocol = http
services.is.context = app
#services.is.host = localhost
services.is.host = dev-openaire.d4science.org
#services.is.port = 8280
services.is.port = 443
#services.is.protocol = http
services.is.protocol = https
#services.is.context = app
services.is.context = is
#services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp
@ -15,7 +20,7 @@ openaire.exporter.cxfClientConnectTimeout = 60000
openaire.exporter.cxfClientReceiveTimeout = 120000
# JDBC
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaire
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280
openaire.exporter.jdbc.user = dnetapi
openaire.exporter.jdbc.pwd = dnetPwd
@ -46,9 +51,10 @@ openaire.exporter.findObjectStore = /eu/dnetlib/openaire/xquery/find
openaire.exporter.findFunderContexts = /eu/dnetlib/openaire/xquery/findFunderContexts.xquery
openaire.exporter.findCommunityContexts = /eu/dnetlib/openaire/xquery/findCommunityContexts.xquery
openaire.exporter.findContextProfiles = /eu/dnetlib/openaire/xquery/findContextProfiles.xquery
openaire.exporter.findContextProfilesByType = /eu/dnetlib/openaire/xquery/findContextProfilesByType.xquery
openaire.exporter.getRepoProfile = /eu/dnetlib/openaire/xquery/getRepoProfile.xquery
openaire.exporter.contentLoadQuery = { "$and" : [ { "system:profileName" : "Graph construction [PROD]" }, { "system:isCompletedSuccessfully" : "true" }, { "reuseContent" : "false" } ] }
# REST API CONFIGURATION
openaire.exporter.swaggerDsm.apiTitle = OpenAIRE aggregator REST API
openaire.exporter.swaggerDsm.apiDescription = The OpenAIRE data provision REST API allows developers to access the metadata information space of OpenAIRE programmatically.
@ -101,4 +107,4 @@ openaire.exporter.swaggerInfo.apiContactEmail = ${openaire.exporter.swaggerD
# VOCABULARIES
openaire.exporter.vocabularies.baseUrl = http://localhost:8980/provision/mvc/vocabularies
openaire.exporter.vocabularies.countriesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:countries.json
openaire.exporter.vocabularies.datasourceTypologiesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:eosc_datasource_types.json
openaire.exporter.vocabularies.datasourceTypologiesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:datasource_typologies.json

View File

@ -1,12 +1,7 @@
#services.is.host = localhost
services.is.host = dev-openaire.d4science.org
#services.is.port = 8280
services.is.port = 443
#services.is.protocol = http
services.is.protocol = https
#services.is.context = app
services.is.context = is
#services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
services.is.host = localhost
services.is.port = 8280
services.is.protocol = http
services.is.context = app
services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp
@ -20,7 +15,7 @@ openaire.exporter.cxfClientConnectTimeout = 60000
openaire.exporter.cxfClientReceiveTimeout = 120000
# JDBC
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaire
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280
openaire.exporter.jdbc.user = dnetapi
openaire.exporter.jdbc.pwd = dnetPwd
@ -51,10 +46,9 @@ openaire.exporter.findObjectStore = /eu/dnetlib/openaire/xquery/find
openaire.exporter.findFunderContexts = /eu/dnetlib/openaire/xquery/findFunderContexts.xquery
openaire.exporter.findCommunityContexts = /eu/dnetlib/openaire/xquery/findCommunityContexts.xquery
openaire.exporter.findContextProfiles = /eu/dnetlib/openaire/xquery/findContextProfiles.xquery
openaire.exporter.findContextProfilesByType = /eu/dnetlib/openaire/xquery/findContextProfilesByType.xquery
openaire.exporter.getRepoProfile = /eu/dnetlib/openaire/xquery/getRepoProfile.xquery
openaire.exporter.contentLoadQuery = { "$and" : [ { "system:profileName" : "Graph construction [PROD]" }, { "system:isCompletedSuccessfully" : "true" }, { "reuseContent" : "false" } ] }
# REST API CONFIGURATION
openaire.exporter.swaggerDsm.apiTitle = OpenAIRE aggregator REST API
openaire.exporter.swaggerDsm.apiDescription = The OpenAIRE data provision REST API allows developers to access the metadata information space of OpenAIRE programmatically.
@ -107,4 +101,4 @@ openaire.exporter.swaggerInfo.apiContactEmail = ${openaire.exporter.swaggerD
# VOCABULARIES
openaire.exporter.vocabularies.baseUrl = http://localhost:8980/provision/mvc/vocabularies
openaire.exporter.vocabularies.countriesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:countries.json
openaire.exporter.vocabularies.datasourceTypologiesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:datasource_typologies.json
openaire.exporter.vocabularies.datasourceTypologiesEndpoint = ${openaire.exporter.vocabularies.baseUrl}/dnet:eosc_datasource_types.json

View File

@ -1,18 +0,0 @@
package eu.dnetlib.openaire.exporter.exceptions;
public class CommunityNotFoundException extends Exception {
/**
*
*/
private static final long serialVersionUID = -5605421323034135778L;
public CommunityNotFoundException(final String msg) {
super(msg);
}
public CommunityNotFoundException(final Exception e) {
super(e);
}
}

View File

@ -0,0 +1,24 @@
package eu.dnetlib.openaire.exporter.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = -5605421323034135778L;
public ResourceNotFoundException(final String msg) {
super(msg);
}
public ResourceNotFoundException(final Exception e) {
super(e);
}
public ResourceNotFoundException(){super();}
}