api for removeConstaint

This commit is contained in:
Michele Artini 2023-07-05 11:20:53 +02:00
parent aebac32457
commit 891b49a9d6
2 changed files with 61 additions and 1 deletions

View File

@ -346,7 +346,7 @@ public class CommunityApiController {
})
public void removeCommunityOrganization(
@PathVariable final String id,
@RequestBody final String organizationId) throws CommunityException {
@RequestParam final String organizationId) throws CommunityException {
communityService.removeCommunityOrganizations(id, organizationId);
}
@ -514,6 +514,40 @@ public class CommunityApiController {
return communityService.removeCommunityAdvancedConstraint(id);
}
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "the set of constraints to be used to remove the association between result and community", description = "the set of constraints to be used to remove the association between result and community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails addRemoveConstraint(
@PathVariable final String id,
@RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
return communityService.addCommunityRemoveConstraint(id, removeConstraint);
}
@RequestMapping(value = "/community/{id}/removeConstraint", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "remove the constraints to remove the association beetween result and community", description = "remove the constraints to remove the association beetween result and community", tags = {
C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityDetails removeRemoveConstraint(@PathVariable final String id) throws CommunityException {
return communityService.removeCommunityRemoveConstraint(id);
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
"application/json"
}, method = RequestMethod.POST)

View File

@ -365,6 +365,32 @@ public class CommunityService {
}
}
@Transactional
public CommunityDetails addCommunityRemoveConstraint(final String id, final SelectionCriteria removeConstraint) throws CommunityException {
try {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
dbEntry.setRemoveConstraints(removeConstraint);
dbCommunityRepository.save(dbEntry);
return getCommunity(id);
} catch (final Throwable e) {
log.error(e);
throw new CommunityException(e);
}
}
@Transactional
public CommunityDetails removeCommunityRemoveConstraint(final String id) throws CommunityException {
try {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
dbEntry.setRemoveConstraints(null);
dbCommunityRepository.save(dbEntry);
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)
throws CommunityException {
if (isMain) {