logs and bug fix
This commit is contained in:
parent
3ae2207d38
commit
95a522d8d0
|
@ -82,7 +82,7 @@ public class CommunityApiController {
|
||||||
"application/json"
|
"application/json"
|
||||||
}, method = RequestMethod.POST)
|
}, method = RequestMethod.POST)
|
||||||
@Operation(summary = "update community details", description = "update community details", tags = {
|
@Operation(summary = "update community details", description = "update community details", tags = {
|
||||||
C, R
|
C, W
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ -107,7 +107,7 @@ public class CommunityApiController {
|
||||||
@ApiResponse(responseCode = "404", description = "not found"),
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Page<CommunityProject> getCommunityProjects(@PathVariable final String id, @PathVariable final int page, final int size)
|
public Page<CommunityProject> getCommunityProjects(@PathVariable final String id, @PathVariable final Integer page, @PathVariable final Integer size)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
return communityService.getCommunityProjects(id, page, size);
|
return communityService.getCommunityProjects(id, page, size);
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ public class CommunityApiController {
|
||||||
@ApiResponse(responseCode = "404", description = "not found"),
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
|
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
|
||||||
return communityService.getPropagationOrganizationCommunityMap();
|
return communityService.getPropagationOrganizationCommunityMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +552,7 @@ public class CommunityApiController {
|
||||||
@ApiResponse(responseCode = "404", description = "not found"),
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Set<String> getPropagationOrganizationsForCommunity(@PathVariable final String communityId) {
|
public Set<String> getPropagationOrganizationsForCommunity(@PathVariable final String communityId) throws CommunityException {
|
||||||
return communityService.getPropagationOrganizationsForCommunity(communityId);
|
return communityService.getPropagationOrganizationsForCommunity(communityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,7 +568,7 @@ public class CommunityApiController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Set<String> addPropagationOrganizationForCommunity(@PathVariable final String communityId,
|
public Set<String> addPropagationOrganizationForCommunity(@PathVariable final String communityId,
|
||||||
@RequestParam final String organizationId) {
|
@RequestParam final String organizationId) throws CommunityException {
|
||||||
return communityService.addPropagationOrganizationForCommunity(communityId, organizationId);
|
return communityService.addPropagationOrganizationForCommunity(communityId, organizationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ public class CommunityApiController {
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public Set<String> removePropagationOrganizationForCommunity(@PathVariable final String communityId,
|
public Set<String> removePropagationOrganizationForCommunity(@PathVariable final String communityId,
|
||||||
@RequestParam final String organizationId) {
|
@RequestParam final String organizationId) throws CommunityException {
|
||||||
return communityService.removePropagationOrganizationForCommunity(communityId, organizationId);
|
return communityService.removePropagationOrganizationForCommunity(communityId, organizationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
@ -64,43 +66,75 @@ public class CommunityService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DbSubCommunityRepository dbSubCommunityRepository;
|
private DbSubCommunityRepository dbSubCommunityRepository;
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(CommunityService.class);
|
||||||
|
|
||||||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
||||||
|
try {
|
||||||
return dbCommunityRepository.findAll()
|
return dbCommunityRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunitySummary)
|
.map(CommunityMappingUtils::toCommunitySummary)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
|
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
|
||||||
|
try {
|
||||||
dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
|
dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
|
||||||
return getCommunity(details.getId());
|
return getCommunity(details.getId());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
return CommunityMappingUtils.CommunityDetails(c);
|
return CommunityMappingUtils.CommunityDetails(c);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
|
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
CommunityMappingUtils.populateCommunity(c, details);
|
CommunityMappingUtils.populateCommunity(c, details);
|
||||||
dbCommunityRepository.save(c);
|
dbCommunityRepository.save(c);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<CommunityProject> getCommunityProjects(final String id, final int page, final int size) throws CommunityException, ResourceNotFoundException {
|
public Page<CommunityProject> getCommunityProjects(final String id, final int page, final int size) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return dbProjectRepository.findByCommunity(id, PageRequest.of(page, size)).map(CommunityMappingUtils::toCommunityProject);
|
return dbProjectRepository.findByCommunity(id, PageRequest.of(page, size)).map(CommunityMappingUtils::toCommunityProject);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
|
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbProject p = CommunityMappingUtils.toDbProject(id, project);
|
final DbProject p = CommunityMappingUtils.toDbProject(id, project);
|
||||||
dbProjectRepository.save(p);
|
dbProjectRepository.save(p);
|
||||||
return project;
|
return project;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList)
|
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final List<DbProject> list = projectList.stream()
|
final List<DbProject> list = projectList.stream()
|
||||||
.map(p -> CommunityMappingUtils.toDbProject(id, p))
|
.map(p -> CommunityMappingUtils.toDbProject(id, p))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -108,36 +142,60 @@ public class CommunityService {
|
||||||
dbProjectRepository.saveAll(list);
|
dbProjectRepository.saveAll(list);
|
||||||
|
|
||||||
return projectList;
|
return projectList;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityProject(final String id, final String projectId) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityProject(final String id, final String projectId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
dbProjectRepository.deleteById(new DbProjectPK(id, projectId));
|
dbProjectRepository.deleteById(new DbProjectPK(id, projectId));
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityProjectList(final String id, final List<String> projectIdList) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityProjectList(final String id, final List<String> projectIdList) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final List<DbProjectPK> list = projectIdList.stream()
|
final List<DbProjectPK> list = projectIdList.stream()
|
||||||
.map(projectId -> new DbProjectPK(id, projectId))
|
.map(projectId -> new DbProjectPK(id, projectId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dbProjectRepository.deleteAllById(list);
|
dbProjectRepository.deleteAllById(list);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return dbDatasourceRepository.findByCommunity(id)
|
return dbDatasourceRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunityContentprovider)
|
.map(CommunityMappingUtils::toCommunityContentprovider)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
|
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbDatasource ds = CommunityMappingUtils.toDbDatasource(id, cp);
|
final DbDatasource ds = CommunityMappingUtils.toDbDatasource(id, cp);
|
||||||
dbDatasourceRepository.save(ds);
|
dbDatasourceRepository.save(ds);
|
||||||
return cp;
|
return cp;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityContentprovider> addCommunityContentProvidersList(final String id, final List<CommunityContentprovider> contentprovidersList)
|
public List<CommunityContentprovider> addCommunityContentProvidersList(final String id, final List<CommunityContentprovider> contentprovidersList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final List<DbDatasource> list = contentprovidersList.stream()
|
final List<DbDatasource> list = contentprovidersList.stream()
|
||||||
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
|
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -145,41 +203,70 @@ public class CommunityService {
|
||||||
dbDatasourceRepository.saveAll(list);
|
dbDatasourceRepository.saveAll(list);
|
||||||
|
|
||||||
return contentprovidersList;
|
return contentprovidersList;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityContentProvider(final String id, final String contentproviderId) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityContentProvider(final String id, final String contentproviderId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, contentproviderId));
|
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, contentproviderId));
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityContentProviderList(final String id, final List<String> contentProviderIdList)
|
public void removeCommunityContentProviderList(final String id, final List<String> contentProviderIdList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final List<DbDatasourcePK> list = contentProviderIdList.stream()
|
final List<DbDatasourcePK> list = contentProviderIdList.stream()
|
||||||
.map(dsId -> new DbDatasourcePK(id, dsId))
|
.map(dsId -> new DbDatasourcePK(id, dsId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
dbDatasourceRepository.deleteAllById(list);
|
dbDatasourceRepository.deleteAllById(list);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityOrganization(final String id, final String organizationId) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityOrganization(final String id, final String organizationId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, organizationId));
|
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, organizationId));
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return dbSupportOrgRepository.findByCommunity(id)
|
return dbSupportOrgRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toCommunityOrganization)
|
.map(CommunityMappingUtils::toCommunityOrganization)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
|
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbSupportOrg o = CommunityMappingUtils.toDbSupportOrg(id, organization);
|
final DbSupportOrg o = CommunityMappingUtils.toDbSupportOrg(id, organization);
|
||||||
dbSupportOrgRepository.save(o);
|
dbSupportOrgRepository.save(o);
|
||||||
return organization;
|
return organization;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityOrganization> addCommunityOrganizationList(final String id, final List<CommunityOrganization> orgList)
|
public List<CommunityOrganization> addCommunityOrganizationList(final String id, final List<CommunityOrganization> orgList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final List<DbSupportOrg> list = orgList.stream()
|
final List<DbSupportOrg> list = orgList.stream()
|
||||||
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
|
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -187,27 +274,46 @@ public class CommunityService {
|
||||||
dbSupportOrgRepository.saveAll(list);
|
dbSupportOrgRepository.saveAll(list);
|
||||||
|
|
||||||
return orgList;
|
return orgList;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSubCommunity(final String id, final String subCommunityId) throws CommunityException, ResourceNotFoundException {
|
public void removeSubCommunity(final String id, final String subCommunityId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
dbSubCommunityRepository.deleteById(subCommunityId);
|
dbSubCommunityRepository.deleteById(subCommunityId);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SubCommunity> getSubCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<SubCommunity> getSubCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return dbSubCommunityRepository.findByCommunity(id)
|
return dbSubCommunityRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(CommunityMappingUtils::toSubCommunity)
|
.map(CommunityMappingUtils::toSubCommunity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCommunity addSubCommunity(final SubCommunity sub) {
|
public SubCommunity addSubCommunity(final SubCommunity sub) throws CommunityException {
|
||||||
|
try {
|
||||||
final DbSubCommunity sc = CommunityMappingUtils.toDbSubCommunity(sub);
|
final DbSubCommunity sc = CommunityMappingUtils.toDbSubCommunity(sub);
|
||||||
dbSubCommunityRepository.save(sc);
|
dbSubCommunityRepository.save(sc);
|
||||||
return sub;
|
return sub;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SubCommunity> addSubCommunityList(final List<SubCommunity> subs) {
|
public List<SubCommunity> addSubCommunityList(final List<SubCommunity> subs) throws CommunityException {
|
||||||
|
try {
|
||||||
final List<DbSubCommunity> list = subs.stream()
|
final List<DbSubCommunity> list = subs.stream()
|
||||||
.map(CommunityMappingUtils::toDbSubCommunity)
|
.map(CommunityMappingUtils::toDbSubCommunity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -215,47 +321,90 @@ public class CommunityService {
|
||||||
dbSubCommunityRepository.saveAll(list);
|
dbSubCommunityRepository.saveAll(list);
|
||||||
|
|
||||||
return subs;
|
return subs;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
|
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
|
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
|
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
|
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
|
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
|
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
|
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setAdvancedConstraints(advancedCosntraint);
|
dbEntry.setAdvancedConstraints(advancedCosntraint);
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
|
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
|
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
|
||||||
|
try {
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
dbEntry.setAdvancedConstraints(null);
|
dbEntry.setAdvancedConstraints(null);
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
||||||
|
@ -269,21 +418,31 @@ public class CommunityService {
|
||||||
|
|
||||||
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
try {
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
|
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
|
||||||
} else {
|
} else {
|
||||||
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
|
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
|
||||||
}
|
}
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private CommunityDetails updateElementToSimpleField(final String id,
|
private CommunityDetails updateElementToSimpleField(final String id,
|
||||||
final BiConsumer<DbCommunity, String> setter,
|
final BiConsumer<DbCommunity, String> setter,
|
||||||
final String value) throws ResourceNotFoundException, CommunityException {
|
final String value) throws ResourceNotFoundException, CommunityException {
|
||||||
|
try {
|
||||||
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
setter.accept(dbEntry, value);
|
setter.accept(dbEntry, value);
|
||||||
dbCommunityRepository.save(dbEntry);
|
dbCommunityRepository.save(dbEntry);
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -315,40 +474,70 @@ public class CommunityService {
|
||||||
return getCommunity(id);
|
return getCommunity(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getOpenAIRECommunities(final String zenodoId) {
|
public List<String> getOpenAIRECommunities(final String zenodoId) throws CommunityException {
|
||||||
|
try {
|
||||||
return dbCommunityRepository.findByZenodoId(zenodoId);
|
return dbCommunityRepository.findByZenodoId(zenodoId);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
|
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() throws CommunityException {
|
||||||
|
try {
|
||||||
return dbOrganizationRepository.findAll()
|
return dbOrganizationRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
|
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) {
|
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) throws CommunityException {
|
||||||
|
try {
|
||||||
return dbOrganizationRepository.findByCommunity(communityId)
|
return dbOrganizationRepository.findByCommunity(communityId)
|
||||||
.stream()
|
.stream()
|
||||||
.map(DbOrganization::getOrgId)
|
.map(DbOrganization::getOrgId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<String> addPropagationOrganizationForCommunity(final String communityId, final String organizationId) {
|
public Set<String> addPropagationOrganizationForCommunity(final String communityId, final String organizationId) throws CommunityException {
|
||||||
|
try {
|
||||||
final DbOrganization o = new DbOrganization(communityId, organizationId);
|
final DbOrganization o = new DbOrganization(communityId, organizationId);
|
||||||
dbOrganizationRepository.save(o);
|
dbOrganizationRepository.save(o);
|
||||||
return getPropagationOrganizationsForCommunity(communityId);
|
return getPropagationOrganizationsForCommunity(communityId);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<String> removePropagationOrganizationForCommunity(final String communityId, final String organizationId) {
|
public Set<String> removePropagationOrganizationForCommunity(final String communityId, final String organizationId) throws CommunityException {
|
||||||
|
try {
|
||||||
final DbOrganization o = new DbOrganization(communityId, organizationId);
|
final DbOrganization o = new DbOrganization(communityId, organizationId);
|
||||||
dbOrganizationRepository.delete(o);
|
dbOrganizationRepository.delete(o);
|
||||||
return getPropagationOrganizationsForCommunity(communityId);
|
return getPropagationOrganizationsForCommunity(communityId);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConceptSummary> listSubConcepts(final String conceptId, final boolean all) {
|
public List<ConceptSummary> listSubConcepts(final String conceptId, final boolean all) throws CommunityException {
|
||||||
|
try {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import eu.dnetlib.openaire.community.model.DbProject;
|
import eu.dnetlib.openaire.community.model.DbProject;
|
||||||
|
@ -11,6 +11,6 @@ import eu.dnetlib.openaire.community.model.DbProjectPK;
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
public interface DbProjectRepository extends JpaRepository<DbProject, DbProjectPK> {
|
public interface DbProjectRepository extends JpaRepository<DbProject, DbProjectPK> {
|
||||||
|
|
||||||
Page<DbProject> findByCommunity(String community, PageRequest page);
|
Page<DbProject> findByCommunity(String community, Pageable page);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
package eu.dnetlib.openaire.exporter.exceptions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class CommunityException extends Exception {
|
public class CommunityException extends Exception {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +11,7 @@ public class CommunityException extends Exception {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityException(final IOException e) {
|
public CommunityException(final Throwable e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue